我已经通过 SendGrid 的模板引擎创建了一个“感谢订阅”电子邮件模板。
现在,当有人订阅我的网站时,我想向他发送该模板。我可以使用 sendgrid-nodejs 来做到这一点吗?包?
我在文档中没有看到任何关于此的内容。
最佳答案
是的,这真的很简单,您只需将其添加为过滤器即可。它应该是这样的:
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!');
}
});
希望对你有所帮助。如果您需要更深入地了解它,请查看我写的关于 using Template Engine with sendgrid-nodejs 的博文。 .
关于node.js - 使用 sendgrid Node 模块,如何发送 SendGrid 模板引擎电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29031169/