Node.js 使用SendGrid';为密件抄送收件人添加替换;s节点库
我的用例是这样的,我需要发送一封包含多个密件抄送收件人的电子邮件,每个收件人都有自己的替换项 我试图使用一些静态测试数据。我可以使用密件抄送收件人创建邮件,但是,每个收件人都会收到最后一组替换值 以下是我的代码的相关部分:Node.js 使用SendGrid';为密件抄送收件人添加替换;s节点库,node.js,sendgrid,sendgrid-api-v3,Node.js,Sendgrid,Sendgrid Api V3,我的用例是这样的,我需要发送一封包含多个密件抄送收件人的电子邮件,每个收件人都有自己的替换项 我试图使用一些静态测试数据。我可以使用密件抄送收件人创建邮件,但是,每个收件人都会收到最后一组替换值 以下是我的代码的相关部分: const mail = new helper.Mail(); const personalization = new helper.Personalization(); const testData = [ { email: 'recipient1@gmail.
const mail = new helper.Mail();
const personalization = new helper.Personalization();
const testData = [
{
email: 'recipient1@gmail.com',
name: 'Bob Smith',
dollars: '100',
points_for_play: '2500',
},
{
email: 'recipient2@gmail.com',
name: 'Mary Smith',
dollars: '50',
points_for_play: '1000',
},
];
testData.forEach(function(recipientData) {
var substitutionValues = _.omit(recipientData, ['email', 'name']);
var bccRecipient = new helper.Email(recipientData.email, recipientData.name);
personalization.addBcc(bccRecipient);
_.forOwn(substitutionValues, function(value, key) {
var substitution = new helper.Substitution('%' + key + '%', value);
personalization.addSubstitution(substitution);
});
});
mail.addPersonalization(personalization);
结果是,每个密件抄送收件人将收到最后的替换值:
%dollars% = 50
%points_for_play% = 1000
我还尝试为每个密件抄送收件人创建一个新的个性化设置,但这会导致一个错误,指出个性化设置实例需要一个“to”数组,这似乎不正确。。。哪里出错了?自2017年7月起,v3 API中还不支持BCC替换,但根据SendGrid支持,它们在SMTP API中