【问题标题】:Sending raw HTML to email hoganjs template via nodejs gives raw HTML output on email client通过 nodejs 将原始 HTML 发送到电子邮件 hoganjs 模板会在电子邮件客户端上提供原始 HTML 输出
【发布时间】:2016-11-19 08:10:10
【问题描述】:

我有一个 Angular 前端应用程序,它发送一个 http POST 请求,其中包含以下原始 HTML 作为正文:

<h1>Hello World</h1><ol><li>Yo</li><li>Bro</li></ol>

我的nodejs 后端使用sendgrid 发送它,我也使用HoganJs 进行模板。

但是我在我的电子邮件中收到了这个。

更新

nodejs-sendgrid

sendgrid.send({
    to:       req.body.mail.email || "",
    replyto: "someemail@gmail.com",
    from:     "someemail@gmail.com",
    subject:  req.body.mail.subj,
    html:     template.render(req.body.mail),
}, function(err, json) {
    // do something
});

【问题讨论】:

  • 你能展示你的 Node.js 代码吗?特别是发送函数和调用。如果您使用 Sendgrid Node.js 帮助程序库,就像使用它一样
  • 好吧,我只是将原始字符串 req.body.mail.body 发送到 template.render(req.body.mail); @Iceman
  • 助手有一个setHtml。它设置了正确的标题!

标签: javascript html angularjs node.js hogan.js


【解决方案1】:
sendgrid.send({
    to:       req.body.mail.email || "",
    replyto: "someemail@gmail.com",
    from:     "someemail@gmail.com",
    subject:  req.body.mail.subj,
    html:     "<b>Hello World</b>",
}, function(err, json) {
    // do something
});

【讨论】:

  • 分解它。而不是 hogan 尝试使用像“Hello World”这样的html字符串,看看会发生什么
  • 它有效,但有点难看,因为我的模板太长了。
  • 我猜这有点“hacky”。你能更新你的答案吗?
  • 你能 console.log template.render(req.body.mail) 看看发生了什么。仍然不明白为什么它不起作用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-13
  • 2014-06-02
  • 1970-01-01
  • 2019-11-21
  • 1970-01-01
  • 2022-10-23
  • 1970-01-01
相关资源
最近更新 更多