【发布时间】:2016-02-27 11:48:52
【问题描述】:
我正在向单个用户发送一封交易电子邮件,并希望在电子邮件中嵌入项目列表。我可以使用 Node.js 中的 NPM 包“sendgrid”添加单个替换值 - https://github.com/sendgrid/sendgrid-nodejs:
email.addFilter('templates', 'enable', 1);
email.addFilter('templates', 'template_id', '11122233445....');
email.addSubstitution('{{TOKEN1}}', 'My Token1 Replacement');
但我看不到如何将项目列表添加到 sendgrid 中的模板。使用 Mandrill 我可以使用 Handlebars 并执行以下操作。名单:
items: [
{name: "one", url: "/one"},
{name: "two", url: "/two"},
];
在模板中:
<ul>
{{#each ITEMS}}
<li>
{{name}} - <a href="{{url}}">Blah</a>
</li>
{{/each}}
</ul>
然后在代码中:
var rcpt = { "rcpt": email,
"vars": [
{ "name":"ITEMS", "content": items }
]
};
mergeVars.push(rcpt);
var message = { ...
"merge_vars": mergeVars,
}
mandrillClient.messages.sendTemplate({... "message": message });
导致:
<ul>
<li>one <a href="/one">Blah</a></li>
<li>two <a href="/two">Blah</a></li>
</ul>
有没有办法在 Sendgrid 中做到这一点?
【问题讨论】:
标签: node.js email templates sendgrid mandrill