6

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>
user3226932
  • 2,042
  • 6
  • 39
  • 76
  • 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 Jul 16 '16 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 Jul 16 '16 at 23:58
  • `/resetpw` this is a relative URL ! – Ismail RBOUH Jul 16 '16 at 23:58
  • @user3226932 They likely won't trust your link with **no** `href`, either. – ceejayoz Jul 16 '16 at 23:59
  • Also, you've got two `id` attributes. Start with code that *should* work before you complain that it *doesn't*. – ceejayoz Jul 17 '16 at 00:00
  • 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 Jul 17 '16 at 00:02
  • You need the `http://`. Send an email with `Test` - no IDs, no targets, just the bare minimum. If *that* fails, you've got some other problem going on. – ceejayoz Jul 17 '16 at 00:04
  • @ceejayoz i see. what about url's with query parameters, like this one? Test. this has the http:// in it but stackoverflow shorttend it for some reason – user3226932 Jul 17 '16 at 00:12
  • are there a list of examples of valid href values that gmail accepts? i couldn't find any online – user3226932 Jul 17 '16 at 00:21
  • 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 Jul 17 '16 at 00: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.com` as the domain, not `localhost` or `example.com`. – ceejayoz Jul 17 '16 at 00:26
  • If you using nodemailer, check the solution [here](https://stackoverflow.com/questions/41946783/gmail-blocking-small-embedded-inline-images-in-email-template/68532260#68532260) – Marvin Correia Jul 26 '21 at 15:09

3 Answers3

7

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.com/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.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
1

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.

0

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.

Hardik Shah
  • 166
  • 1
  • 10