如何使用nodemailer发送邮件而不出现错误500



我在尝试使用nodemailer发送邮件时收到错误代码500。我是Firebase函数和express。看看我的代码,告诉我哪些地方做得不对。

const gmailEmail = functions.config().gmail.login;
const gmailPassword = functions.config().gmail.pass;
admin.initializeApp();
app.post('/visitor/contact', (req, res, next) => {
return cors()(req, res, () => {
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
//transporter is a way to send your emails
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: gmailEmail,
pass: gmailPassword
}
});
// setup email data with unicode symbols
//this is how your email are going to look like
const mailOptions = {
from: gmailEmail,
to: req.body.email,
subject: 'Full stack developer',
html: `<h1 style="color:blue;">Welcome ${req.body.firstName}</h1>
<p style="font-size:25px;">Thank you very much for contacting me. i hope you are having a great time where ever you may be.</p>
<p style="font-size:25px;">I am a full stack developer by training and i am available at the moment for a MEAN stack job That will challenge me to be better.</p>
<p style="font-size:23px;">Thanks ${req.body.firstName}</p>`
};
transporter.sendMail(mailOptions);
next();
});
});

您没有对res.send((或res.json((进行任何调用,因此服务器不会返回响应。所以我相信下一个变量可能是未定义的,所以在调用之前,您可能需要测试它的无效值

相关内容

  • 没有找到相关文章

最新更新