我有一个快速应用程序,并且我创建了一个在本地工作并发送测试电子邮件的联系表。
我已经为不同的环境设置了 nodemailer,目前两者都在使用刻录机测试电子邮件。
但是,一旦我将其推送到 Zeit 现在。POST 请求根本不会触发。任何帮助表示赞赏。
GLOBAL_EMAIL 环境在生产中的应用程序上设置。
router.post('/contact/send', (req, res) => {
// async..await is not allowed in global scope, must use a wrapper
async function main() {
const output = `
<h3>You have a new contact message!</h3>
<ul>
<li><b>Name:</b> ${ req.body.name }</li>
<li><b>Email:</b> ${ req.body.email }</li>
<li><b>Phone Number:</b> ${ req.body.phone_number }</li>
</ul>
<h3>Message:</h3>
<p>${ req.body.message }</p>
`;
var mailConfig ;
if (process.env.NODE_ENV === 'production' ){
mailConfig = {
host: "smtp.mailtrap.io", // smtp.sendgrid.net
port: 2525, // 587
auth: {
user: "a3ad3f28b0982c", // a48aef40aa09bf
pass: "64f3d499b1d6d2" // 222473c0a9e6e9
}
};
} else {
mailConfig = {
host: "smtp.mailtrap.io",
port: 2525,
auth: {
user: "a3ad3f28b0982c", // a48aef40aa09bf
pass: "64f3d499b1d6d2" // 222473c0a9e6e9
}
};
}
let transporter = nodemailer.createTransport(mailConfig);
// send mail with defined transport object
let info = await transporter.sendMail({
from: `"${req.body.name}" <${req.body.email}>`, // sender address
to: process.env.GLOBAL_EMAIL || 'ben@benbagley.dev', // list of receivers
subject: 'New contact message', // Subject line
html: output // html body
});
console.log('Message sent: %s', info.messageId);
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
}
main().catch(console.error);
});