Javascript 如何在node js中发送html电子邮件模板?
我只想每封邮件发送一次存储在doc中的数据,但邮件可能会发送两次,因为我使用了映射doc。你知道一封信怎么寄吗 例如: 在一封电子邮件中Javascript 如何在node js中发送html电子邮件模板?,javascript,node.js,express,nodemailer,Javascript,Node.js,Express,Nodemailer,我只想每封邮件发送一次存储在doc中的数据,但邮件可能会发送两次,因为我使用了映射doc。你知道一封信怎么寄吗 例如: 在一封电子邮件中 const doc = [ {id: 1, name: 'test1', title: 'hello1', email: 'name@gmail.com'}, {id: 2, name: 'test2', title: 'hello2', email: 'name2@gmail.com'}, {id: 3, name: 'test1', title: 'h
const doc = [
{id: 1, name: 'test1', title: 'hello1', email: 'name@gmail.com'},
{id: 2, name: 'test2', title: 'hello2', email: 'name2@gmail.com'},
{id: 3, name: 'test1', title: 'hello3', email: 'name@gmail.com'},
{id: 4, name: 'test2', title: 'hello4', email: 'name2@gmail.com'}
]
{doc.map(data =>
let emailTemplate = fs.readFileSync('./emailTemplates/story-likes.html', { encoding: 'utf-8' });
emailTemplate = emailTemplate.replace('[name]', data.name);
emailTemplate = emailTemplate.replace('[title]', data.title);
const mailOptions = {
from: 'info@domain.com',
to: doc.email,
subject: "Test Subject",
html: emailTemplate
}
transporter.sendMail(mailOptions, (err, info) => {
if (err) {
console.log(err);
}
})
})}
在另一封电子邮件中:
name: test1,
title: hello
name: test2,
title: hello3
映射功能与两次发送邮件无关。很可能整个函数正在运行两次我有折射我的问题。
name: test1,
title: hello2
name: test2,
title: hello4