【发布时间】:2015-11-25 00:38:44
【问题描述】:
我有一个 HTML sendgrid 模板,并使用 npm 包“sendgrid”通过 Node.js 发送它。问题是我总是以文本格式而不是 HTML 格式接收电子邮件,即使模板有 HTML。
代码:
var email = new sendgrid.Email({
to : 'me@here.com',
from : 'you@there.com',
subject : 'Saying Hi with HTML Template',
text : 'Body' //This is required
});
email.addFilter('templates', 'enable', 1);
email.addFilter('templates', 'template_id', '12131331.....');
email.addSubstitution('{{TOKEN1}}', 'value');
sendgrid.send(email, function(err, json) {
if (err) { console.error(err); }
console.log(json);
});
模板
<html>
<head><title></title></head>
<body>
<h1>This is a test</h1>
<p>{{TOKEN1}}</p>
<p><a href="http://www.there.com">There</a></p>
<div><%body%></div>
</body>
</html>
是否有我应该设置的代码参数?还是模板本身的设置允许 HTML?
【问题讨论】:
-
检查documentation。您需要设置电子邮件对象的 HTML,而不是文本。
-
我明白了,谢谢。 即使不需要也是必需的。
-
我相信 'text' 是电子邮件客户端不支持 HTML 电子邮件的后备方案。
-
是的。我在想我可以把我所有的 html 放在模板中并且只使用替换,但我看到我必须至少放一个“。”在 html 字段中。
标签: html node.js email sendgrid