发送消息时,Sendgrid SMTP API不会replacereplace标记

我正在开发一个Node.js应用程序,它将Sendgrid事务电子邮件模板包含在用户邀请函中。 具体来说,我使用Ubuntu w /官方sendgrid v2 npm上的nodejs v0.10.25。 我实际发送消息的function如下:

function sendEmail(payload, options, cb){ //for debugging purposes console.log(options); var email = new sendgrid.Email({ subject: payload.subject, html: payload.html, from: global.config.sendgrid.mailFrom, fromname: global.config.sendgrid.mailName, replyto: options.replyto ? options.replyto : 'no-reply@' + global.config.sendgrid.mailhost }); email.setSmtpapiTos(options.addressees); if(options.filters) email.setFilters(options.filters); if(options.subs) email.setSubstitutions(options.subs); if(options.category) email.setCategories(options.category); if(options.unique_args) email.setUniqueArgs(options.unique_args); sendgrid.send(email, function(err, json){ return cb(err, json); }); } 

包含replace的选项对象如下所示:

 { category: 'Support Invite', addressees: [ %EMAIL1%, %EMAIL2% ], sub: { '-name-': [ 'Shawn 1', 'Shawn 2' ], '-id-': [ 1, 2 ], '-pic-': [ '<img height="100" src="%PICTURE URL%?sz=50" style="width: 100px; height: 100px;" width="100" />', '<img height="100" src="%PICTURE URL%?sz=50" style="width: 100px; height: 100px;" width="100" />' ] }, filters: { templates: { settings: { 'enable': 1, 'template_id': global.config.sendgrid.transactions.supportInvite} } }, unique_args: { sender: '104294048950213400380' } } 

最后,这个testing的模板HTML:

 <html> <head> <title></title> </head> <body> <div style="text-align: center;"><span>-pic-</span></div> <div><span style="font-family:tahoma,geneva,sans-serif;">Hello -name-,</span></div> <div>&nbsp;</div> <div><span style="font-family:tahoma,geneva,sans-serif;">&lt;%body%&gt;</span></div> <div>&nbsp;</div> <div>&nbsp;</div> <div>&nbsp;</div> <div><span style="font-family:tahoma,geneva,sans-serif;"><span style="font-size:9px;">Invitation ID:</span>&nbsp;-id-</span></div> </body> </html> 

邮件以正确的模板,主题和发件人信息发送给相应的收件人。 我也可以从我的SendGrid统计中validation它们是用适当的类别和SMTP参数(“发件人”)标记的。 但替代没有完成 。 例如,我的testing邮箱中的-name-标签依然存在于结果邮件中。

我已经尝试了SendGrid的咨询文档,包括他们的SMTP API,并查询了他们的支持数据库。 我也search过StackExchange,但最相关的问题( 这个 , 这个和这个 )并没有提供一个答案。 特别有趣的是,每个人都使用不同的字符替代标记。 不知道这是纯粹的select还是语言依赖。 我尝试了不同的字符( – ,:和%),但结果相同。

我看到你的选项对象有一个属性sub,而不是subs。 option.subs将永远是未定义的,因此是错误的

如果(options.subs)

要么尝试改变

如果(options.sub)

或者从sub到subs选项中重命名属性。