【问题标题】:How to send localhost link using Sendgrid and Node.js如何使用 Sendgrid 和 Node.js 发送 localhost 链接
【发布时间】: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


    【解决方案1】:

    sendgrid 的一项功能是跟踪您在消息中嵌入的链接的点击次数。那个长 URL 就是点击跟踪器:它会从他们的服务器反弹到您的服务器。

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

    您也可以告诉它您不想跟踪该链接或整个模板。我不知道该怎么做,抱歉。

    【讨论】:

      猜你喜欢
      • 2020-11-20
      • 1970-01-01
      • 1970-01-01
      • 2017-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-19
      相关资源
      最近更新 更多