18

I am using Ruby on Rails 3 and I would like to disable an email address link in a HTML email.

For example, if in an email I send some raw HTML like

Hi, you email is: <br/>
test@email.com

Gmail autodetects that this is an email address and changes it to

Hi, you email is: <br/>
<a target="_blank" href="mailto:test@email.com">test@email.com</a>

I would like to have this output

# Text without the 'mailto:' link
Hi, you email is:
test@email.com

How can I do that?

PaulG
  • 13,871
  • 9
  • 56
  • 78
user502052
  • 14,803
  • 30
  • 109
  • 188
  • Or can be converted into image with some jQuery intervention or even PHP? –  Sep 15 '11 at 13:07

10 Answers10

35

I have a more natural suggestion: wrap the email/url in an anchor hyperlink.

<a name="myname">test@email.com</a>

Since the text is already wrapped in a hyperlink, Gmail gives up and leave it alone. :)

(Note: also worked for Apple mail client.)

raugfer
  • 1,844
  • 19
  • 19
9

By 2021, the best for me would be:

<a href='#' style='text-decoration: none; color:#000000' name='myname'>x@somemail.com</a>

Explanation

After trying different services like Gmail, Outlook 365, Mailinator, and MyTrashMail, the results are:

<a> - wrapping the email into anchor is essential, as raugfer pointed

href='#' is necessary for Outlook. Linking to a fake anchor disables following the link.

text-decoration: none, color:#000000 removes underline and changes color from blue link color to natural text color. For those who want not only to disable the link but make its appearance as usual text.

name='myname' wouldn't harm, however, I haven't noticed its necessity.

Any javascript should be avoided, it won't pass Gmail. E.g. onClick="return false;", <script>...</script>.

If you want to change the cursor to default, cursor: default or cursor: auto won't help. For Gmail only, do without href='#'

Using <span> or <myspan> works for Gmail as Prince Mishra stated, but it doesn't help in all the services (in Outlook, for instance).

HoRn
  • 1,458
  • 5
  • 20
  • 25
  • Outlook online strips the anchor tag completely out though if it is set to `href="#"` – Rob Sep 22 '21 at 04:41
  • @Rob, I checked with Outlook online (outlook.office365.com), and it seems fine to me. The link is disabled. Hope it is disabled for you, too? Sorry, I don't see the problem – HoRn Sep 28 '21 at 19:52
2

Even I had the same problem. Gmail would detect and convert mail addresses and ip addresses to links. I used string.replace to enclose dots (.) and @ in blocks. And that works fine for me. sample python code looks like.

text = myname@gmail.com
chars = ['.','@']
encloseIn = 'span'

for char in chars:
    text = string.replace(text, char, '<'+encloseIn+'>'+char+'</'+encloseIn+'>')
Prince Mishra
  • 311
  • 2
  • 9
2

This is what worked for me in Laravel.

<a style="pointer-events: none; color: inherit">
    {{$user->email}}
</a>
Edward
  • 31
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 10 '22 at 13:42
1

You can try

Hi, you email is:<br />
test&#64;email&#46;com
Syfer
  • 4,262
  • 3
  • 20
  • 37
rubyprince
  • 17,559
  • 11
  • 64
  • 104
1

Late reply but i think I have found a way to get over this auto linking issue.

The easiest and fastest way is to add a zero width non joiner between each alphabets. Now that sounded hard so I developed a small script that made things easy for me. Run the code below, add email address (paste or type) and it adds the required code around the email address. Paste the result in your email.

$('#userInput').keyup(function() {
    var s = $(this).val().trim();
    var text = "";
    for ( var i = 0; i < s.length; i++ )
        {
            text += s[i]+'&zwnj;' ;
        } 
    $('p').text( text );
});
#userInput{max-width:400px;width:100%;padding:10px 5px;}
*{outline:none;}
p,#userInput{font-family: 'Roboto', sans-serif;}
p{word-break:break-all;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<input type="text" id="userInput" />

<p></p>
Syfer
  • 4,262
  • 3
  • 20
  • 37
0

Reading all answers, I tried this in a Joomla article and it worked:

<p><strong>This is the email address: </strong><a name="whatever">youremail&#64domain.com</a></p>

Result:

This is the email address: youremail@domain.com

Worked on Chrome and Firefox.

0

You can just break the email address in half with an invisible space.

test<span style="display: none;">&nbsp;</span>@email.com

The <span> puts a space in the email, but the style prevents the space from displaying. As far as the browser is concerned, the text is "test @email.com", but it displays as "test@email.com" and will even allow the user to cut and paste the email without the space.

-1

You just need to add the "zero width space" character, his code in HTML is:

&#8203;

This code adds a space in the string where you need. For a respectable solution you need to complement this method with a <nobr> tag, because with this tag you can prevent from breaking to the next line.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
fractefactos
  • 353
  • 4
  • 10
-3

The only way to get around this is to convert the email address into an image and include that in the email. Of course this means the user might choose to not download the image, which would mean they won't get the email address either.

What it really comes down to is that you can't control what Gmail or any other email client does once it receives an email, so there isn't another way around this. It's Gmail's, or any other email client's, choice to do what they want with emails, and that includes hyper-linking email addresses.

If you are very adamant about not converting emails into hyperlinks you can try to do other things to conceal the fact that it's an email, like writing it out instead:

Hi, your email is:
test at email dot com

Of course this is probably more confusing. If I were you, I would simply settle for the fact that Gmail will hyper-link your emails.

Pan Thomakos
  • 34,082
  • 9
  • 88
  • 85
  • The method of converting the email into an image is partly acceptable because as you said recipient may not download images. Indeed no system will add a link to the image, yet I guess the downsides why some people dislike it are: 1) you can't quickly change the address. You need to re-render the image (programatically); 2) impossible to copy-paste the address. Embedding the image as encoded – HoRn May 22 '21 at 08:47