67

Problem is Gmail automatically creates hyperlinks for all website URLs and email addresses. I do not want to create a link.

var mailClient = new SmtpClient();
var netMail = new MailMessage();

msg = "I do not want www.google.com as a link at recipient end. <br/>";
msg += "I want my email addrress myemail@myudomain.com as html without a link";

var cr = new NetworkCredential("########", "###########");

netMail.From = new MailAddress("########@m####.###", "######");
netMail.To.Add(new MailAddress("abc@xyz.com"));
netMail.Subject = "Test Mail";
netMail.IsBodyHtml = true;
netMail.Body = msg;

mailClient.Host = "xyz.com";
mailClient.Port = 25;
mailClient.EnableSsl = false;
mailClient.Credentials = cr;
mailClient.Send(netMail);

Any solution?

informatik01
  • 16,038
  • 10
  • 74
  • 104
Manjoor
  • 4,091
  • 10
  • 43
  • 67

13 Answers13

56

I had a same issue and found out if you use email like this;

<a rel="nofollow" style='text-decoration:none; color:#333'>test@mydomain.com</a>

email providers does not tend to follow email as a link.

Hope this helps.

Teoman shipahi
  • 47,454
  • 15
  • 134
  • 158
  • This is nice solution, works in Gmail, Outlook and others. Not working with Apple Mail.app though. – psimekjr Feb 26 '14 at 10:44
  • 1
    @Psimekjr I was running into the same issue with Apple mail. You MUST include an href attribute (even if it's value is #) – user1380540 May 20 '16 at 20:32
  • 1
    Clean solution with actual docs :D https://support.google.com/webmasters/answer/96569?hl=en – Bogdan M. Nov 07 '19 at 08:17
  • 1
    @BogdanM. this says nothing about links in emails – T Tse Dec 16 '20 at 08:52
  • @ShioT it does actually state pretty clear how attributes determine link behaviour in chrome products - gmai lincluded. – Bogdan M. Dec 16 '20 at 10:02
  • 2
    @BogdanM. No, that is under the SEO section of the Google Search documentation intended to be read by webmasters. It is about how the `rel` attribute tells Google's web crawler what to do. There is no crawler crawling your emails yet as far as I am concerned, and how Google indexes their search engine definitely has nothing to do with whether a URL in an email appears as a link within gmail. – T Tse Dec 16 '20 at 15:24
35

There's no way to stop creating URLs, because its automatically checked by the email provider that whether the text is a valid URL.

Only way to overcome this is, deceiving the parser. Just put spaces, HTML tags, whatever in such a way that the parser can't identify like URL etc.

Here are a few code examples:

http:<span>//foolishedsiteparser.com</span>
_http://www.parsersmashed.com
noonesemail<x>@</x>linkdead.com>

And the result is the following:

http://foolishedsiteparser.com
_http://www.parsersmashed.com
noonesemail@linkdead.com

informatik01
  • 16,038
  • 10
  • 74
  • 104
perilbrain
  • 7,961
  • 2
  • 27
  • 35
  • Its not working. Gmail replaced tag with automatically @perilbrain – Amanjot Kaur Apr 12 '16 at 12:51
  • 2
    not sure why this is accepted, but answers below are significantly more semantically meaningful and so more likely to be standardized / work in other clients – Andrey Fedorov Jul 20 '18 at 17:53
  • @AndreyFedorov yeah, you can always see the date when the answer is posted and the date when it is accepted :) So maybe at that time, it is worked, but not anymore. – ksugiarto Jul 26 '19 at 10:14
32

I was able to get around this issue just by adding <a style="color: #000000">link text</a> (notice there is no href).

I haven't tried using attributes besides style but I would imagine you could. The email system that I use (Blackbaud NetCommunity) will strip out a plain <a> tag, so I had to have at least one attribute.

Loko Web Design
  • 491
  • 4
  • 11
13

Taking a cue from perilbrain's answer, I implemented the following regex that I use for this:

var unlink = function (val) {
  return val.replace(/([@\.:])/g, '<span>$1</span>');
};

Note that this function replaces globally on whatever is passed in -- it would probably be too aggressive for blocks of natural text as in the OP's example, but often templates are parameterized and this works great when you can just pass it a url or email (I actually implemented it as a template helper function so that it does exactly that).

The function converts the following inputs:

john.doe@gmail.com
http://johndoe.com

into this:

john<span>.</span>doe<span>@</span>gmail<span>.</span>com
http<span>:</span>//johndoe<span>.</span>com

Note that I tried a fake short tag like <x> as shown in the accepted answer and found that GMail "intelligently" replaced it with <u> tags, which I assume is a feature, but was not desirable. In my testing, <span> tags prevent linking with no visual side-effects.

Community
  • 1
  • 1
Brian Moeskau
  • 20,103
  • 8
  • 71
  • 73
  • 1
    working fine but the mail is going in spam now @bmoeskau – Amanjot Kaur Apr 12 '16 at 13:01
  • 1
    Spam filtering is a large and complex topic, and can be triggered at various levels from client to mail server to ISP. There are many factors that play into whether or not emails get marked as spam, and various spam filters work differently. I am doubtful that *this change alone* would cause most spam filters to reject an otherwise normal email, but of course YMMV. – Brian Moeskau Apr 12 '16 at 22:34
10

None of the solutions listed here seem to work any more. I experimented a little with the idea of non-printable Unicode characters and found this sequence to work:

<span>foo&zwnj;.&zwnj;bar&zwnj;.&zwnj;com</span>

Where ‌ is the ZERO WIDTH NON-JOINER character.

Tomek
  • 1,170
  • 11
  • 10
  • Brilliant idea! Also for me, it's the only solution that works – Philipp Sep 08 '20 at 10:11
  • Perfect, only one that worked on Apple mail on iOS for me! – nanuuq Dec 18 '20 at 19:43
  • This works to prevent a link being made, but I need the text to be accurate, so I can copy/paste it somewhere else. The non-printing character is still in there and causes problems wherever it is pasted. Otherwise a good idea. – changokun Sep 07 '21 at 15:24
  • Very smart! Thank you! If someone is using SendGrid it will be needed to triple brackets: `{{{ field }}}` to make it work – Rodrigo João Bertotti Oct 26 '21 at 12:53
8

Nailed it!

This does not prevent emails from being turned into links, but it allows you to set the font color and remove the underline of that link.

It works in all email clients I tested in on litmus.com - including Outlook 2010, 2013, 2016 (also on Windows), Outlook.com, iPhone 6s, iPad, gmail web interface and Apple Mail 8, 9

Variation 1: A link which does not react when clicked upon

<a href="#" style="text-decoration:none; color:#000">bjorn@rosell.dk</a>

Variation 2: A mailto-link. Works in almost all clients. Outlook.com does however style it blue and with underline.

<a href="mailto:bjorn@rosell.dk" style="text-decoration:none; color:#000">bjorn@rosell.dk</a>
rosell.dk
  • 2,228
  • 25
  • 15
7

I have one unmentioned solution for textual emails: Use similar unicode characters. For example one dot leader (U+2024) instead of dot. Compare, how looks Běhej.com and Běhej․com (the first one is with regular dot).

Petr Dlouhý
  • 857
  • 9
  • 11
  • While most other HTML-based tricks on this answer work for Gmail, this is the only one that works for Outlook 2016 as well. Prevents both URLs and email addresses from being clickable or even copy-pasteable! Excellent! – Allon Guralnek Jun 26 '18 at 08:13
  • Exactly what I needed - THANK YOU! I've been looking for a way to type example email addresses like "john@example․com" that don't become blue-underlined or behave like real email addresses in emails I send. This is perfect. – Mark Chapel Aug 14 '18 at 04:30
3

I had a dot com in the title of my confirmation message. Inspired by @perilbrain, I revolved my problem like this

domain.com => domain<span>.</span>

php

$titre = str_replace(".", "<span>.</span>", $titre);

simple !

Andre
  • 89
  • 1
  • 4
1

For now simple wrapping by <span> is not working, I suggest replace @ by its html-entity alternative

function disable_email_link($email) {
  //encoder https://mothereff.in/html-entities
  $email = str_replace('@', '&#x40;', $email);
  $email = str_replace('.', '<span>.</span>', $email);
  return $email;
}

Also if your email contains phone numbers you can escape it by disable_tel_link function:

function wrap_span_letters($string) {
  $res = "";
  $length = strlen($string);
  for ($i = 0; $i < $length; $i++) {
    $res .= "<span>$string[$i]</span>";
  }
  return $res;
}

function disable_tel_link($phone) {
  return wrap_span_letters($phone);
}
Lukas Pierce
  • 807
  • 3
  • 9
  • 15
0

Eventhough this is a old thread i want to help people who might get here. I found that adding a span inside the link makes google not see it as a link see below:

<a href="https://www.link.dk" style="text-decoration: none   !important; color: #878787 !important;">www.<span></span>link.dk</a>
Anoxy
  • 873
  • 7
  • 17
0

i had the same problem so after few mins found out how to fix it.

the thing is if you target the element directly it won't work because gmail will automatically add aa "a" tag in there so you have to go one step farther and declare a class for that "a" tag. in my case the email was in a "" tag which i found it easier to work with. so what i did was create a class like this:

.email_contact a {color:#ffffff!important; text-decoration: none!important;}

there is no "a" tag in my code but since gmail will add it automatically then you should catch it there. now you just have to use that class where ever you put your email add such as "span" or "div" and boom! fixed.

0

While not the ideal solution, it may be an option for some. As of 3/12/2020, If you disable Multipart and send plain text only emails, you'll get the following hyperlinked results. Results appear to be the same whether at the beginning of a new line/sentence or mid sentence.

gmail results for linked email or url via plain text

johnsampson
  • 376
  • 3
  • 14
-1

Suppose your display url is "abcdUrl.com" To prevent gmail from showing as a link, wrap it in an anchor tag

<a href="" style="text-decoration:none;color:#333;"> abcdUrl.com </a>

This works well in gmail.