本文介绍了使用SendGrid节点模块,我如何发送SendGrid模板引擎电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经通过SendGrid的模板引擎创建了"感谢订阅"电子邮件模板。
现在,当有人订阅我的站点时,我希望将该模板发送给该人。我可以使用sendgrid-nodejs程序包执行此操作吗?我在文档中没有看到任何与此相关的内容。
推荐答案是的,这真的很简单,您只需将其作为筛选器添加即可。下面是它应该是什么样子:
var cardEmail = new sendgrid.Email({ to: "theuser@somedomain", from: "bignews@yourdomain", 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的博客文章。
更多推荐
使用SendGrid节点模块,我如何发送SendGrid模板引擎电子邮件?
发布评论