我正在尝试使用nodemailer发送邮件。该脚本可在本地计算机上运行,但是我无法在Azure移动服务中包含nodemailer。在我的package.json中添加了'nodemailer':“ *”,但仍然无法包含它。
日志说
TypeError:无法读取未定义的属性“ prototype”
我注释掉了完整的逻辑,但错误仍然存在。终于注释掉了
var nodemailer = require('nodemailer');
错误消失了。
最佳答案
要解决此问题,您需要安装旧版本的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
关于node.js - Azure移动服务上的nodemailer无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26753793/