我正在尝试使用nodemailer发送邮件。该脚本适用于本地计算机,但我无法在azure移动服务中包含nodemailer。在我的package.json中添加了“nodemailer”:“*”但仍然无法包含它。
日志说
TypeError:无法读取未定义
的属性'prototype'我评论了完整的逻辑,但错误仍然存在。最后评论说 var nodemailer = require('nodemailer');
并且错误消失了。
答案 0 :(得分:0)
要解决此问题,您需要安装较旧版本的nodemailer,以便它可以在Azure移动服务上运行。我在package.json中为Azure添加了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: "gmail.user@gmail.com",
pass: "userpass"
}
});
// setup e-mail data with unicode symbols
var mailOptions = {
from: "Fred Foo ✔ <foo@blurdybloop.com>", // sender address
to: "bar@blurdybloop.com, baz@blurdybloop.com", // 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
});