Sendgrid / Node.js-如何发送本地链接

问题描述 投票:1回答:1

我想使用sendgrid和node.js发送电子邮件,以添加电子邮件验证功能。我在sendgrid仪表板内设置了一个事务模板,但是我不知道如何在我的html中插入一个url(内部,我知道他们为此使用了把手)。模板看起来像(仅重要部分):

模板

<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);
}

但是当我收到电子邮件时,链接看起来像:enter image description here

node.js templates html-email sendgrid
1个回答
1
投票

sendgrid的功能是跟踪您嵌入到邮件中的链接的点击率。较长的网址就是点击跟踪链接:它从他们的服务器反弹到您的服务器。

对于电子邮件验证,您不需要这种跟踪。当我使用sendgrid进行这种操作时,我不使用它们的模板功能,而只是在告诉sendgrid将其逐字发送之前在程序中格式化消息。

© www.soinside.com 2019 - 2024. All rights reserved.