我已经通过SendGrid的模板引擎创建了一个“感谢订阅”电子邮件模板。
现在,当有人订阅我的网站,我想发送那个人的模板。我可以使用sendgrid-nodejs包来完成这个任务吗?
我在文档里没有看到任何关于这个的东西。
发布于 2015-03-13 16:15:39
是的,这很简单,你只需要把它作为一个过滤器加入进来。它应该是这样的:
var cardEmail = new sendgrid.Email({
to: "theuser@somedomain.com",
from: "bignews@yourdomain.com",
subject: process.env.SUBJECT,
html: '<h2>Thanks for requesting a business card!</h2>', // This fills out the <%body%> tag inside your SendGrid template
});
// Tell SendGrid which template to use, and what to substitute. You can use as many substitutions as you want.
cardEmail.setFilters({"templates": {"settings": {"enabled": 1, "template_id": "325ae5e7-69dd-4b95-b003-b0109f750cfa"}}}); // Just replace this with the ID of the template you want to use
cardEmail.addSubstitution('-greeting-', "Happy Friday!"); // You don't need to have a substitution, but if you want it, here's how you do that :)
// Everything is set up, let's send the email!
sendgrid.send(cardEmail, function(err, json){
if (err) {
console.log(err);
} else {
console.log('Email sent!');
}
});
希望这能帮到你。如果你需要更多的洞察力,请看我写的关于在sendgrid-nodejs中使用模板引擎的博客文章。
发布于 2015-03-13 13:34:53
看起来您需要使用SMTPAPI的app(filters)方法来发送模板。我认为它还没有得到web的支持。这里有一些文档:
https://stackoverflow.com/questions/29031169
复制相似问题