简体   繁体   中英

How to send localhost link using Sendgrid and Node.js

I want to send emails with sendgrid and node.js for adding an email-validation feature. I set up a transactional template within the sendgrid dashboard, but I don't know how to insert an url into my html (internally I know they are using handlebars for this). The template looks like (only important part):

template

<a target='_blank' href="{{verificationLink}}" class='link2' style="color:#474747">Verify Email Address</a>

I added the {{verificationLink}} for the dynamic prop and my node-request looks like this:

Node.js code

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

But when I receive the email the link looks like:

在此处输入图片说明

A feature of sendgrid is tracking clickthroughs on the links you embed in your messages. That long URL is the clickthrough tracker: it bounces from their server to yours.

For email validation you don't want that kind of tracking. When I do this sort of thing with sendgrid, I don't use their templating feature, but just format the message in my program before telling sendgrid to send it verbatim.

You may also be able to tell it you don't want tracking on that link or that whole template. I don't know how to do that, sorry.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM