Html 如何防止mailto链接垃圾邮件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3624667/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:21:12  来源:igfitidea点击:

How to spamproof a mailto link?

htmlencodingobfuscationspammailto

提问by Wookai

I want visitors to be able to click on (or copy) an email address directly on my webpage. However, if I could make it (a little bit) harder for bots and other crawlers to get said email address and register it in a spam list, it would be awesome.

我希望访问者能够直接在我的网页上单击(或复制)电子邮件地址。但是,如果我能让机器人和其他爬虫程序(稍微)更难获取所述电子邮件地址并将其注册到垃圾邮件列表中,那就太棒了。

I found different ways of doing this (i.e. encoding mailto HTML links), either with JavaScript or in pure HTML, but what do you guys recommend ? The JavaScript techniques seem more complicated, but this may potentially affect users that have it turned off, and legit crawlers like Google.

我找到了不同的方法来做到这一点(即编码 mailto HTML 链接),无论是使用 JavaScript 还是纯 HTML,但是你们推荐什么?JavaScript 技术看起来更复杂,但这可能会影响关闭它的用户,以及像谷歌这样的合法爬虫。

On the other hand, the HTML one seems a bit basic, the bot writers should have figured it out by now...

另一方面,HTML 似乎有点基础,机器人编写者现在应该已经弄清楚了......

Should I bother at all doing this, or will the spammers get my email anyway ? I know that antispam filters are getting better and better, but if I can do something more to slow spammers down, I will.

我应该费心去做这件事,还是垃圾邮件发送者会收到我的电子邮件?我知道反垃圾邮件过滤器越来越好,但如果我能做更多的事情来减缓垃圾邮件发送者的速度,我会的。

采纳答案by Daniel Vassallo

JavaScript remains one of the best mailto obfuscator. For users with JavaScript disabled you may want to substitute the mailto link with a link to a contact form.

JavaScript 仍然是最好的 mailto 混淆器之一。对于禁用 JavaScript 的用户,您可能希望将 mailto 链接替换为指向联系表单的链接。

The following is a popular JavaScript anti spam email obfuscator:

下面是一个流行的 JavaScript 反垃圾邮件混淆器:

There is also a php versionof the above to be able to generate obfuscated emails from the server side.

上面还有一个 php 版本,可以从服务器端生成混淆的电子邮件。

This is the JavaScript code that the above tool would generate to obfuscate my email address (comments intact):

这是上述工具将生成的用于混淆我的电子邮件地址的 JavaScript 代码(评论完好无损):

<script type="text/javascript" language="javascript">
<!--
// Email obfuscator script 2.1 by Tim Williams, University of Arizona
// Random encryption key feature by Andrew Moulden, Site Engineering Ltd
// This code is freeware provided these four comment lines remain intact
// A wizard to generate this code is at http://www.jottings.com/obfuscator/
{ coded = "[email protected]"
  key = "1DtzZ8TGBuhRjJMKWI4gkUF2qidfOyPmSN7X30Vpso6xvErLnwQCbalA95HcYe"
  shift=coded.length
  link=""
  for (i=0; i<coded.length; i++) {
    if (key.indexOf(coded.charAt(i))==-1) {
      ltr = coded.charAt(i)
      link += (ltr)
    }
    else {     
      ltr = (key.indexOf(coded.charAt(i))-shift+key.length) % key.length
      link += (key.charAt(ltr))
    }
  }
  document.write("<a href='mailto:"+link+"'>Email Me</a>")
}
//-->
</script><noscript><a href='contact-form.html'>Email Me</a></noscript>

回答by Harry

This looks like a really cool method that encodes the characters, which I assume would defeat basic spam bots:

这看起来是一种非常酷的编码字符的方法,我认为它会打败基本的垃圾邮件机器人:

http://robspangler.com/blog/encrypt-mailto-links-to-stop-email-spam/

http://robspangler.com/blog/encrypt-mailto-links-to-stop-email-spam/

So

所以

<a href="mailto:[email protected]">Email</a>

becomes

变成

<a href="&#x6d;&#97;&#105;&#108;&#x74;&#111;&#58;&#116;&#101;&#115;&#116;&#x40;&#x74;&#101;&#115;&#x74;&#x2e;&#x63;&#111;&#109;">Email</a>

It's appealing in that it doesn't require any Javascript.

它的吸引力在于它不需要任何 Javascript。

Plunker example here.

Plunker 示例在这里

回答by jensgram

You coulduse the reCAPTCHA Mailhidefunctionality. This will render email addresses on the form [email protected]where the ellipsis is a link to view the full address. It is a little cumbersome for the visitor but should give premium protection. Having said that, this technique will notlet your visitors copy the address directly from your webpage.

可以使用reCAPTCHA Mailhide功能。这将在表单上呈现电子邮件地址,[email protected]其中省略号是查看完整地址的链接。这对游客来说有点麻烦,但应该提供高级保护。话虽如此,这种技术不会让您的访问者直接从您的网页复制地址。

I don't get the part about the "legit crawlers" like Google. At least, I am unable to see why Google should index the email address anyway.(See OPs comment below.)

我不明白像谷歌这样的“合法爬虫”的部分。至少,我不明白为什么 Google 应该将电子邮件地址编入索引。(请参阅下面的 OP 评论。)

回答by Harry

Building on Daniel Vassallo's answer, one way to encrypt a mailto link that mayavoid cleverer spambots that will evaluate JS document.writes (as pointed out by incarnate) would be to put the decryption in a Javascript function that is only evaluated when the link is clicked on. For example, using base64 as the "encryption":

建立在丹尼尔·瓦萨洛的回答,单程加密一个mailto链接,避免聪明的反垃圾邮件插件,将评估JS document.writeS(由化身指出的)将是把解密的JavaScript函数点击链接时只计算. 例如,使用 base64 作为“加密”:

<script>

  function decryptEmail(encoded) {

    var address = atob(encoded);
    window.location.href = "mailto:" + address;

  }

</script>

<a href="javascript:decryptEmail('dGVzdEB0ZXN0LmNvbQ==');">Email</a>

Working Plunker.

工作Plunker

I don't claim to know whether this could or could not be outsmarted by a more sophisticated crawler.

我不知道这是否可以被更复杂的爬虫超越。

回答by James

You can use external services like aemail.com:

您可以使用aemail.com等外部服务:

@email is a free e-mail hiding service that hides emails using short URLs redirecting senders to the mailto-url after clicking the link.

@email 是一种免费的电子邮件隐藏服务,它使用短 URL 隐藏电子邮件,在单击链接后将发件人重定向到 mailto-url。

After entering an email at aemail.com, you will get a short URL, which can be used to replace your 'mailto' link. Once link is clicked, your user will be redirected to the 'mailto' URL without any notice of the aemail.com. APIcan be used to hide emails/get URLs dynamically.

在 aemail.com 输入电子邮件后,您将获得一个短网址,可用于替换您的“mailto”链接。单击链接后,您的用户将被重定向到“mailto”URL,而不会收到 aemail.com 的任何通知。API可用于动态隐藏电子邮件/获取 URL。

Example:

例子:

<a href="mailto:[email protected]">Contact</a>

<a href="mailto:[email protected]">Contact</a>

Replaced With

替换为

<a href="https://aemail.com/q2">Contact</a>

<a href="https://aemail.com/q2">Contact</a>

Will Keep Email Link Working.

将保持电子邮件链接工作。

回答by HasanG

I simply use:

我只是使用:

<script language="javascript" type="text/javascript">
var pre = "hideme";
document.write("<a href='mailto:" + pre + "@domain.com'>" + pre
+ "@domain.com</a>");
</script>
<noscript>Enable javascript to see our email!</noscript>

回答by Alex B.

My version generates the link on the fly from a base64-encoded email string when the user hovers over the link, or if on a mobile device, touches it. All links with the attribute 'data-gen-email' will work.

当用户将鼠标悬停在链接上或在移动设备上触摸它时,我的版本会从 base64 编码的电子邮件字符串动态生成链接。所有具有“data-gen-email”属性的链接都将起作用。

// The string is your base64-encoded email
const emailAddress = atob("bWFpbHRvOnlvdUBkb21haW4uY29t");

// Select all links with the attribute 'data-gen-email'
const emailLinks = document.querySelectorAll('[data-gen-email]');

emailLinks.forEach(link => {
    link.onmouseover = link.ontouchstart = () => link.setAttribute('href', emailAddress);
});

You can encode your email to base64 by using btoa('mailto:[email protected]'), or elsewhereon the web:

您可以使用btoa('mailto:[email protected]'), 或网络上的其他地方将您的电子邮件编码为 base64 :

btoa('mailto:[email protected]'); // "bWFpbHRvOnlvdUBkb21haW4uY29t"

Example link in html:

html 中的示例链接:

<a href="#" target="_blank" data-gen-email>Email Me!</a>