使用SendGrid节点模块,我如何发送SendGrid模板引擎电子邮件?

编程入门 行业动态 更新时间:2024-10-21 18:59:39
本文介绍了使用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模板引擎电子邮件?

本文发布于:2023-11-06 06:37:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1562960.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   模块   电子邮件   模板   引擎

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!