【发布时间】:2021-01-19 13:14:45
【问题描述】:
我正在使用 nodemailer 向多个用户发送邮件,但我遇到了这个问题,我有一个这样的 json 文件:
[
{
"email": "dotam1236@gmail.com",
"content": "this email send for dotam1236@gmail.com"
},
{
"email": "sale.shopeeholic@gmail.com",
"content": "this email send for sale.shopeeholic@gmail.com"
},
{
"email": "ducminhtuhp@gmail.com",
"content": "this email send for ducminhtuhp@gmail.com"
},
{
"email": "xrodell3@vimeo.com",
"content": "this email send for xrodell3@vimeo.com"
},
{
"email": "pbeadle4@cnet.com",
"content": "this email send for pbeadle4@cnet.com"
}
]
如您所见,每封电子邮件都有一组收件人和内容,这是我的 nodemailer 代码:
var transporter = nodemailer.createTransport({
service: "Gmail",
auth: {
user: "your@gmail.com", // please modify it into your gmail
pass: "yourpassword!" // please modify it into your password of gmail and remove it when you success
}
});
var mailOptions = {
from: "sale.shopeeholic@gmail.com",
to: "dotam1236@gmail.com, sale.shopeeholic@gmail.com",
cc: "sale.shopeeholic@gmail.com",
subject: "Test",
text: "nodemailer send multiple receivers successfully"
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log(error);
return res.status(400).json({ message: "error in sending mail", error });
} else {
return res.status(200).json({ message: "mail sent" });
}
});
我如何为上面json中的每个电子邮件地址发送带有特定内容的邮件,非常感谢您帮助我,如果您不介意,请在codeandbox链接中修改它here(服务器是ExpressJs 不过没关系,影响不大)
在该链接中,您应该使用自己的 gmail 和电子邮件密码进行修改,但我向上帝发誓,我永远不会让它侵入您的个人信息,您可以使用您的个人信息并在成功后将其删除。再次非常感谢你。希望你有美好的一天
【问题讨论】:
标签: javascript email gmail backend nodemailer