这将发送电子邮件。 但是没有替代品可以代替模板。 我只是遵循了“事务性模板”部分中提到的两个示例,并对此进行了尝试。 但是没有什么可以用定义的替换来替换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>
标头为<%subject%>
这是我的代码。
sgMail.setSubstitutionWrappers('{{', '}}'); // Configure the substitution tag wrappers globally
const msg = {
to: '[email protected]',
from: '[email protected]',
subject: 'Hello world',
text: 'Hello plain world!',
html: '<p>Hello HTML world!</p>',
templateId: 'd-5d04c39e40054d118b4de3fba82a09ac',
substitutions: {
name: "Some One",
city: "Denver"
},
};
sgMail.send(msg);
这会发送电子邮件,但是会收到这样的邮件
Hello ,
I'm glad you are trying out the template feature!
<%body%>
I hope you are having a great day in :)
主题为<%subject%>
。
您要共享的与报告的问题有关的任何其他信息。 特别是,为什么您认为这是一个错误? 您期望发生什么呢?
我期待这样的电子邮件(主题为Hello world
)
Hello Some One,
I'm glad you are trying out the template feature!
I hope you are having a great day in Denver :)
在模板引擎中进行了测试,测试数据为
{
"name": "Some One",
"city": "Denver"
}
这在模板引擎中正确显示。
我有同样的问题。 当从@sendmail/helpers
通过Mail.create
构建邮件时,我得到mail.substitutions
= null
@ bbbneo333检查中给出的最后解决这个问题。 对我有用
是。 用personalizations.0.dynamic_template_data
代替substitutions
为我工作。 谢谢。
感谢您帮助@ pankaja92并感谢@ bbbneo333的跟进!
问题是,如果您使用的是新的动态模板,则API调用会有所不同。 我将很快更新此SDK的文档以反映这些更改。
最有用的评论
感谢您帮助@ pankaja92并感谢@ bbbneo333的跟进!
问题是,如果您使用的是新的动态模板,则API调用会有所不同。 我将很快更新此SDK的文档以反映这些更改。