[英]why cant i send emails using nodemailer and nodejs?
我正在嘗試使用 node.js 和 nodemailer 發送 email 但是當我按下提交按鈕時,它只是加載和加載,最后在服務器中給我一個“504網關超時錯誤”,並且在本地“頁面不工作” .
我正在使用以下代碼:
app.post("/postmail", function (req, res) {
var transporter = nodemailer.createTransport({
host: "smtp.mailtrap.io",
port: 2525,
secure: false,
debug: true,
auth: {
user: "xxx",
password: "xxx",
},
});
var message = {
from: "a@b", // Sender address
to: "b@c", // List of recipients
subject: "Design Your Model S | Tesla", // Subject line
text: "Have the most fun you can in a car. Get your Tesla today!", // Plain text body
};
transporter.sendMail(message, function (err, info) {
if (err) {
console.log(err);
} else {
console.log(info);
res.render("landing");
}
});
});
我還必須提到,我嘗試了多個具有多個端口和配置的 smtp 服務器。
有人知道該怎么做嗎?
謝謝
出於安全原因,所有 smtp 提供商都使用 tls/ssl。 嘗試使用安全配置:
var transporter = nodemailer.createTransport({ 主機:'smtp.mailtrap.io',端口:465,安全:真,
debug: true,
auth: {
user: 'xxx',
password: 'xxx'
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.