Nodemailer的sendMail函数返回“undefined”

嗨!

我有以下代码。 注释info.response永远不会执行, info.response返回“undefined”。 你能帮我弄清楚为什么它返回“未定义”,为什么评论部分不被执行,请?

非常感谢你。

app.js:

 app.get('/send', function (req, res) { var mailOptions = { from: req.query.from, to: 'chul@stackexchange.com', subject: 'Applicant', text: req.query.name + req.query.content }; console.log(mailOptions); transport.sendMail(mailOptions, function (error, info) { if (error) { console.log(error); res.end("error"); } else { console.log("Message sent: " + info.repsonse); res.end("sent"); // This part does NOT get executed. }; }); }); 

index.html的:

  <script type='text/javascript'> $(document).ready(function() { var from, name, content; $("#send_app").click(function() { from = $("#from").val(); name = $("#name").val(); content = $("#content").val(); $("message").text("Submitting the application ..."); $.get("http://localhost:3000/send", { from: from, name: name, content: content }, function(data) { if (data == "sent") { // This block does NOT get executed console.log("sent received"); $("#message").empty().html("The e-mail has been sent."); } else { console.log(data); } }); }); }); </script> 

从它的外观,我看不到运输的初始化。 尝试像这样:

 var transport = nodemailer.createTransport({ service: 'SendGrid', auth: { user: yourUserName, pass: yourPassword } }); // Then the transport you initialized var mailOptions = { from: req.query.from, to: 'chul@stackexchange.com', subject: 'Applicant', text: req.query.name + req.query.content }; console.log(mailOptions); transport.sendMail(mailOptions, function (error, info) { if (error) { console.log(error); res.end("error"); } else { console.log("Message sent: " + info.repsonse); res.end("sent"); // This part does NOT get executed. }; });