admin管理员组

文章数量:1318570

I'm sending an email from my NodeJS server using Mailgun to a Gmail account, but Gmail strips all the attributes in the email. What is the reason for this and how do I prevent this from happening? I tried encoding the href value using encodeURIComponent but that did nothing for the href tag. I'm also not using any CSS or anything so I'm confused why this is happening.

before:

<a href="/resetpw" id="reset-link" id="reset" target="_blank">Reset Password</a>

after (when I checked the HTML of the email):

<a></a>

I'm sending an email from my NodeJS server using Mailgun to a Gmail account, but Gmail strips all the attributes in the email. What is the reason for this and how do I prevent this from happening? I tried encoding the href value using encodeURIComponent but that did nothing for the href tag. I'm also not using any CSS or anything so I'm confused why this is happening.

before:

<a href="/resetpw" id="reset-link" id="reset" target="_blank">Reset Password</a>

after (when I checked the HTML of the email):

<a></a>
Share Improve this question asked Jul 16, 2016 at 23:54 user3226932user3226932 2,25211 gold badges53 silver badges87 bronze badges 12
  • 2 Chances are they don't trust your href without a domain name in it. Fix that (in part because it's just not going to work without one, anyways). – ceejayoz Commented Jul 16, 2016 at 23:57
  • but even if i take that out and just use the target attribute, that target attribute gets removed too for some reason – user3226932 Commented Jul 16, 2016 at 23:58
  • 1 @ceejayoz you're right. any ideas on how to go about using a localhost url as the href value (for example: localhost:3000/resetpw) so that gmail doesn't strip that? i tried that but it didn't work. my website isn't hosted on a live site, only on my local – user3226932 Commented Jul 17, 2016 at 0:02
  • 1 StackOverflow turns URLs into links, and shortens the visual display of them. This has nothing to do with your code. Surround your code with ` on each side to prevent the behavior. – ceejayoz Commented Jul 17, 2016 at 0:25
  • 1 Query strings will be fine. All Gmail's likely to require is a valid domain name in the URL, because an email with a href of /foo/bar doesn't make sense because the email's being displayed on mail.google. as the domain, not localhost or example.. – ceejayoz Commented Jul 17, 2016 at 0:26
 |  Show 7 more ments

3 Answers 3

Reset to default 8

Gmail is likely stripping your link from the email because of the href value of /resetpw, which, seeing as it's missing a domain name, will refer to https://mail.google./resetpw and a) not work and b) potentially be a security hole (I can't think of a way off-hand, but it makes sense to be overly cautious here on Google's part).

Use a valid URL with a scheme and domain/IP (i.e. http://localhost:3000/resetpw), fix the invalid HTML like duplicate id parameters, and it should work just fine.

If you still have the problem even with an absolute path then the problem may be because the Sendgrid mail goes directly to the SPAM folder, the same thing happens to me, the links in Gmail do not work but when i move the Spam mail to the general folder manually there the link works correctly.

So the solution is probably fix your Spam situation, but this is an other subject. Here you can find some information.

I had similar issue. I found that gmail removes the links, if we don't add "http://". I added the http tag and it worked fine.

本文标签: