How to disable an email link?

2019-02-12 08:42发布

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?

6条回答
女痞
2楼-- · 2019-02-12 09:00

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+'>')
查看更多
何必那么认真
3楼-- · 2019-02-12 09:08

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.

查看更多
来,给爷笑一个
4楼-- · 2019-02-12 09:16

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.

查看更多
一纸荒年 Trace。
5楼-- · 2019-02-12 09:20

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.)

查看更多
聊天终结者
6楼-- · 2019-02-12 09:21

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.

$('#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>

Now this code didn't work on Outlook Mac's (2011 and 2016). Only way I made it work on these as well was adding to the head of the document and appending HTML

Goes in the head:

<meta content="telephone=no" name="format-detection">
<style>
    p.email a{color:#000000!important;text-decoration:none!important;}
</style>

Change the paragraph, td or table to have a class as email (or whatever you choose)

<p class="email"> contents </p>

Hope this helps users looking for a solution to remove auto links.

查看更多
Evening l夕情丶
7楼-- · 2019-02-12 09:25

You can try

Hi, you email is:<br />
test&#64;email&#46;com
查看更多
登录 后发表回答