[英]nodemailer on azure mobile service not working
我正在嘗試使用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: "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
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.