【发布时间】:2018-08-02 09:26:09
【问题描述】:
在 SendGrids github 上的 USE CASE 之后,确实设法向我发送了带有正确模板的电子邮件,但替换显然不起作用,并且在生成的电子邮件中留空。服务器端:
const sgmailer = require("@sendgrid/mail");
sgmailer.setApiKey(process.env.SENDGRID_API_KEY);
sgmailer.setSubstitutionWrappers('{{', '}}');
const msg = {
to: '...',
from: 'sender@example.org',
subject: 'Hello world',
text: 'Hello plain world!',
html: '<p>Hello HTML world!</p>',
templateId: '...',
substitutions: {
name: 'Some One',
city: 'Denver',
},
};
sgmailer.send(msg)
模板中的 HTML:
<html>
<head>
<title></title>
</head>
<body>
Hello {{name}},
<br /><br/>
I'm glad you are trying out the template feature!
<br /><br/>
<%body%>
<br /><br/>
I hope you are having a great day in {{city}} :)
<br /><br/>
</body>
</html>
我收件箱中的结果电子邮件:
你好,
很高兴您正在试用模板功能!
希望您在 :) 度过愉快的一天
这里的变量显然丢失了。 如何正确替换变量?
【问题讨论】:
标签: javascript node.js sendgrid-api-v3 sendgrid-templates