首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用sendgrid节点模块,如何发送SendGrid模板引擎电子邮件?

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

Stack Overflow用户
提问于 2015-03-13 11:33:34
回答 2查看 4.6K关注 0票数 2

我已经通过SendGrid的模板引擎创建了一个“感谢订阅”电子邮件模板。

现在,当有人订阅我的网站,我想发送那个人的模板。我可以使用sendgrid-nodejs包来完成这个任务吗?

我在文档里没有看到任何关于这个的东西。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-03-13 16:15:39

是的,这很简单,你只需要把它作为一个过滤器加入进来。它应该是这样的:

代码语言:javascript
运行
复制
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中使用模板引擎的博客文章。

票数 14
EN

Stack Overflow用户

发布于 2015-03-13 13:34:53

看起来您需要使用SMTPAPI的app(filters)方法来发送模板。我认为它还没有得到web的支持。这里有一些文档:

API/apps.html#模板

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29031169

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档