Prevent Gmail from creating links for URLs and email addresses

Viewed 63520

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?

13 Answers

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.

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 !

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);
}

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.

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

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.

Related