能否在nodemailer中使用SendGrid的Substitution标签?

3
我正在使用nodemailer和Sendgrid (https://github.com/nodemailer/nodemailer-smtp-transport),我希望一次性向2000个用户发送不同内容的电子邮件。目前,我创建一个SMTP传输并逐一发送我的邮件,但我遇到了问题,我认为最好只发一个请求来发送所有邮件。
使用Sengrid SMTP API,可以通过使用替换标记将邮件发送给许多用户,并定制其内容。使用nodemailer,是否可以使用这些在单个请求中向每个人发送自定义邮件?例如,使用sendgrid节点包 (https://github.com/sendgrid/smtpapi-nodejs) 中的setSubstitutions是可能的,但我想继续使用nodemailer。

类似以下内容:

 smtp.sendMail({  
      from: "Me",  
      to: [ "you@example.com", "him@example.com" ],  
      subs: { "-name-": [ "you", "him" ] },  
      subject: "Your name",  
      html: "<h1>Your name is -name-</h1>"  
    })

It would be much appreciated :)

1个回答

2
您应该能够通过明确设置所需的X-SMTPAPI头来完成此操作。
smtp.sendMail({
  headers: {
    'X-SMTPAPI': '{"sub": { "-name-": ["you","him"] } }'
  },
  from: "Me",  
  to: [ "you@example.com", "him@example.com" ],    
  subject: "Your name",  
  html: "<h1>Your name is -name-</h1>"  
})

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接