Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在node js中发送html电子邮件模板?_Javascript_Node.js_Express_Nodemailer - Fatal编程技术网

Javascript 如何在node js中发送html电子邮件模板?

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

我只想每封邮件发送一次存储在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: '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