【发布时间】:2020-04-07 15:58:11
【问题描述】:
我想使用 sendgrid 和 node.js 发送电子邮件以添加电子邮件验证功能。我在 sendgrid 仪表板中设置了一个事务模板,但我不知道如何将 url 插入到我的 html 中(内部我知道他们为此使用了把手)。模板看起来像(仅重要部分):
模板
<a target='_blank' href="{{verificationLink}}" class='link2' style="color:#474747">Verify Email Address</a>
我为动态道具添加了{{verificationLink}},我的节点请求如下所示:
Node.js 代码
public async sendEmailVerificationLink(data: any) {
const {firstName, email} = data;
const token = Math.random().toString(36).substr(2);
const message: MailData = {
from: EmailCreator.EMAIL_FROM,
personalizations: [{
to: [{
email,
}],
dynamicTemplateData: {
"firstName": firstName,
"verificationLink": `http://localhost:4200/verify-email?token=${token}`
},
}],
templateId: 'd-8ca7682e287d47428c351e7854d98567'
};
return sendgridMail.send(message);
}
但是当我收到电子邮件时,链接看起来像:
【问题讨论】:
标签: node.js templates html-email sendgrid