我正在尝试使用nodemailer发送邮件。该脚本在本地计算机上运行,但我无法将nodemailer包含在azure移动服务中。在我的 package.json 中添加了 'nodemailer' : "*"但仍然无法包含它。
日志说
类型错误:无法读取未定义的属性“原型(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: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c4a3a9a5ada8eab1b7a1b684a3a9a5ada8eaa7aba9" rel="noreferrer noopener nofollow">[email protected]</a>",
pass: "userpass"
}
});
// setup e-mail data with unicode symbols
var mailOptions = {
from: "Fred Foo ✔ <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cfa9a0a08fada3babdabb6ada3a0a0bfe1aca0a2" rel="noreferrer noopener nofollow">[email protected]</a>>", // sender address
to: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="94f6f5e6d4f6f8e1e6f0edf6f8fbfbe4baf7fbf9" rel="noreferrer noopener nofollow">[email protected]</a>, <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1173706b51737d64637568737d7e7e613f727e7c" rel="noreferrer noopener nofollow">[email protected]</a>", // 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
});
关于node.js - Azure 移动服务上的 NodeMailer 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26753793/