问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/40687027/sendgrid-change-href-of-link