要解决此问题,您需要安装旧版本的nodemailer,以便它可以在Azure移动服务中使用。我在Azure的package.json中添加了nodemailer的0.7.1版本,然后进行了必要的代码更改并为我工作。
的代码改变了,你需要做的,以支持0.7.1是非常小的,这里是从文档的完整代码:
var nodemailer = require("nodemailer");
// create reusable transport method (opens pool of SMTP connections)
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "[email protected]",
pass: "userpass"
}
});
// setup e-mail data with unicode symbols
var mailOptions = {
from: "Fred Foo ✔ <[email protected]>", // sender address
to: "[email protected], [email protected]", // list of receivers
subject: "Hello ✔", // Subject line
text: "Hello world ✔", // plaintext body
html: "<b>Hello world ✔</b>" // html body
}
// send mail with defined transport object
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
// if you don't want to use this transport object anymore, uncomment following line
//smtpTransport.close(); // shut down the connection pool, no more messages
});
Nodemailer 0.7.1 documentation
您使用相同(或类似)节点的版本?你在本地使用nodemailer 0.7,但远程使用1.0吗?你可以给一个完整的堆栈跟踪? – RikkusRukkus 2014-11-05 09:46:12
你说得对。我的机器的节点版本是0.10.29,在我的机器上是0.8.28。任何想法如何更新azure移动服务上的nodejs版本?或者如何安装与该版本兼容的依赖关系。 我检查了两个机器上的nodemailer版本,它是相同的(1.3.0)。 – ribhu 2014-11-05 10:36:38
不能帮助你,抱歉。 [根据开发人员](https://github.com/andris9/Nodemailer/issues/346),nodemailer 0.7.1是最后一个兼容0.8的版本。您需要对代码进行一些更改 - nodemailer 1.x与0.x版本不完全兼容。 – RikkusRukkus 2014-11-05 11:02:08