55

I am using Nodejs with Express and I am sending an email through Sendgrid, but Sendgrid is changing the href link

var emailText = '<!DOCTYPE html><html><head><meta charset="UTF-8"></head><body><a href="https://www.google.com">Here</a></body></html>'
var from_email = new helper.Email('contact@test.com');
var to_email = new helper.Email('contact@test2.com');
var subject = 'Test';
var content = new helper.Content("text/html", emailText)
var mail = new helper.Mail(from_email, subject, to_email, content);                                            
var request = sg.emptyRequest({
    method: 'POST',
    path: '/v3/mail/send',
    body: mail.toJSON(),
});
sg.API(request, function(error, response) {
    if (error) {
        console.log('Error response received');
    }
    console.log(response.statusCode);
    console.log(response.body);
    console.log(response.headers);
});

When the email arrives the following link appears:

https://u4006412.ct.sendgrid.net/wf/click?upn=rOQ9fjZGp5r0JyNfoC02LbL.....

Could someone help me solve this problem?

rafaelcb21
  • 12,422
  • 28
  • 62
  • 86

4 Answers4

49

I believe this is caused by the URL click-tracking feature of sendgrid. It will redirect to your intended resource, but does not look pretty. You can turn it off in sendgrid, but it will disable URL tracking on all emails sent by that account. If you are integrating with a 3rd-party link-tracker such as bit.ly or have your GA on lock-down, this may not bother you.

Here's more information on the feature in sendgrid: https://sendgrid.com/docs/User_Guide/Settings/tracking.html

Turn that off and see how your emails look.

UPDATE: Whitelabeling in Sendgrid

Sendgrid also has a whitelabeling feature, allowing you to serve URLs from one of your subdomains while still tracking clicks/opens through their servers. If you are concerned about the prettiness of your links or perceived security from a UX perspective, this may be the way to go.

Check out their overview of whitelabeling and link whitelabeling doc pages. Be sure to follow sendgrid's recommendations on domain usage in emails. This ensures a high success rate on delivery.

Community
  • 1
  • 1
swensor
  • 631
  • 6
  • 6
  • It's worth noting similar links are ADDED to sendgrid with this feature: https://sendgrid.com/docs/User_Guide/Transactional_Email/unsubscribes.html – swensor Nov 18 '16 at 22:56
  • 2
    Keep in mind sometimes it takes some to for this change to take effect. Not much, it took only 5 minutes for me, but it's enough to makes you think it's not working if you do a test right away after the change. – Tahi Reu Aug 06 '20 at 09:11
46

You can off the Sendgrid tracking for one link specifically.
To do so, You have to add clicktracking="off" before your href tag

Do it like this

<a clicktracking="off" href='https://mysite/auth/'>My Site</a>

Bibhudatta Sahoo
  • 4,808
  • 2
  • 27
  • 51
Israa Saifullah
  • 461
  • 4
  • 2
  • 1
    You should update your answer with more details. Mention that this code is used for turning off tracking for individual links, etc. – Zsolt Meszaros Nov 30 '20 at 08:59
  • In case it helps to anyone, apparently some tools like branch.io don't have this issue. But we switched to Firebase Dynamic Links, and links inside emails were opening Google Play app page instead of the mobile app. Adding clicktracking="off" in the Sendgrid template, fixed the issue – moyo Apr 27 '22 at 14:17
8

Similar to @israa-saifullah said, you can state clicktracking="off" directly in an html link, but if you're sending through the sg api, there is a trackingSettings property that you can set on an individual message where you can specify if you want click and open-tracking enabled. clickTracking is what re-writes your URL's, and you can specify it at the HTML or Text based level. For example this disables all tracking and therefore leaves the URL's in the email untouched.

const msg = {
 to: TO_ADDRESSS,
 from: {
   name: FROM_NAME,
   email: FROM_ADDRESSS,
 },
 subject: SUBJECT,
 text: TEXT_VERSION,
 html: HTML_VERSION,
 trackingSettings: {
  clickTracking: {
    enable: false,
    enableText: false
  },
  openTracking: {
    enable: false
  }
}

This is helpful if you don't want to override tracking at the account level (in the SG Dashboard), but just for a specific use case.

Documentation here.

McB
  • 1,082
  • 1
  • 18
  • 36
7

It is possible to change through the sendgrid settings, access the path: settingns -> tracking -> click tracking -> disabled

tracking config

Tiago Viana
  • 91
  • 1
  • 1