【发布时间】:2020-11-16 05:45:43
【问题描述】:
我正在尝试使用 node.js 和 nodemailer 发送电子邮件,但是当我按下提交按钮时,它只是加载和加载,最后在服务器中给我一个“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 服务器。
有人知道该怎么做吗?
谢谢
【问题讨论】:
-
更新我尝试了以下设置:tls:{rejectUnauthorized:false}并将属性“密码”更改为“通过”。现在它只在本地工作,我仍然在服务器上遇到同样的错误。我试图将属性主机更改为:主机:“主机”,但它仍然无法正常工作
-
P.S 现在我收到“0|app | ] 代码:'ESOCKET',命令:'CONN'}”错误
标签: javascript node.js express smtp nodemailer