如何对 mailto 链接进行垃圾邮件防护?

发布于 2024-09-16 19:48:57 字数 355 浏览 11 评论 0 原文

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

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

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

我是否应该费心这样做,或者垃圾邮件发送者无论如何都会收到我的电子邮件?我知道反垃圾邮件过滤器正在变得越来越好,但如果我能采取更多措施来减缓垃圾邮件发送者的速度,我会的。

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.

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

莫相离 2024-09-23 19:48:58

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

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

You could use the reCAPTCHA Mailhide functionality. 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 not let your visitors copy the address directly from your webpage.

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

飞烟轻若梦 2024-09-23 19:48:58

我只是使用:

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

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>
作业与我同在 2024-09-23 19:48:58

当用户将鼠标悬停在链接上或在移动设备上触摸它时,我的版本会根据 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);
});

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

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

html 中的示例链接:

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

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.

// 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 elsewhere on the web:

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

Example link in html:

<a href="#" target="_blank" data-gen-email>Email Me!</a>
記柔刀 2024-09-23 19:48:58
//This sets the mailto link when clicked. 
//As the link is followed, the focus is also lost and the link reset to # 
//html should look like this :
//<a class="courriel" data-courriel="john" data-objet="Just a test" href="#">Some text</a>

$('.courriel').click(function() { 
  var sA = $(this).attr('data-courriel'); // get nickname
  var sO = $(this).attr('data-objet');    // get subject
//Adresses are hard coded here; a nick name is used; 
//this to prevent having a potentially decypherable encoded adress  in the <a> tag
  switch (sA) { 
    case 'john': 
      $(this).attr('href', 'mailto:[email protected]?subject=' + sO);
      break;
    case 'paul':
      $(this).attr('href', 'mailto:[email protected]?subject=' + sO);
      break;
    default:
        $(this).attr('href', '#');
  }


})
$('.courriel').focusout(function() { //reset the link to # on focus loss
    $(this).attr('href', '#');
})
//This sets the mailto link when clicked. 
//As the link is followed, the focus is also lost and the link reset to # 
//html should look like this :
//<a class="courriel" data-courriel="john" data-objet="Just a test" href="#">Some text</a>

$('.courriel').click(function() { 
  var sA = $(this).attr('data-courriel'); // get nickname
  var sO = $(this).attr('data-objet');    // get subject
//Adresses are hard coded here; a nick name is used; 
//this to prevent having a potentially decypherable encoded adress  in the <a> tag
  switch (sA) { 
    case 'john': 
      $(this).attr('href', 'mailto:[email protected]?subject=' + sO);
      break;
    case 'paul':
      $(this).attr('href', 'mailto:[email protected]?subject=' + sO);
      break;
    default:
        $(this).attr('href', '#');
  }


})
$('.courriel').focusout(function() { //reset the link to # on focus loss
    $(this).attr('href', '#');
})
零崎曲识 2024-09-23 19:48:58

完整的反垃圾邮件版本

<div class="at">info<i class="fa fa-at"></i>google.com</div>
OR
<div class="at">info@google.com</div>

<style>
.at {
  color: blue;
  cursor: pointer;
}
.at:hover {
  color: red;
}
</style>

<script>
const el33 = document.querySelector(".at");
el33.onclick = () => {
  let recipient="info";
  let at = String.fromCharCode(64);
  let dotcom="google.com";
  let mail="mailto:";
  window.open(mail+recipient+at+dotcom);
}
</script>

Full AntiSpam version

<div class="at">info<i class="fa fa-at"></i>google.com</div>
OR
<div class="at">info@google.com</div>

<style>
.at {
  color: blue;
  cursor: pointer;
}
.at:hover {
  color: red;
}
</style>

<script>
const el33 = document.querySelector(".at");
el33.onclick = () => {
  let recipient="info";
  let at = String.fromCharCode(64);
  let dotcom="google.com";
  let mail="mailto:";
  window.open(mail+recipient+at+dotcom);
}
</script>
只涨不跌 2024-09-23 19:48:58

这就是我用的。我不知道我在哪里找到的。我根本不懂 javascript,所以需要“Javascript for Dummy's”版本。 :-) 希望我知道如何预先填写主题行。有一天……也许吧。

<script language=javascript>var name = "firstname.lastname@";
document.write ("<a href=\"mailto:" + name + "gmail.com\">John Doe</a>");</script>

结果:[电子邮件受保护]

This is what I use. I don't know where I found it. I'm not javascript savvy at all so needed the "Javascript for Dummy's" version. :-) Wish I knew how to make it pre-fill in a subject line. Someday...maybe.

<script language=javascript>var name = "firstname.lastname@";
document.write ("<a href=\"mailto:" + name + "gmail.com\">John Doe</a>");</script>

Result: [email protected]

栖竹 2024-09-23 19:48:57

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

以下是流行的 JavaScript 反垃圾邮件混淆器:

还有上述的一个 php 版本能够从服务器端生成混淆的电子邮件。

这是上述工具生成的 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>

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.

The following is a popular JavaScript anti spam email obfuscator:

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

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

<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>
信愁 2024-09-23 19:48:57

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

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

因此

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

它很有

<a href="mailto:test@test.com">Email</a>

吸引力,因为它不需要任何 Javascript。

这里是 Plunker 示例

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/

So

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

becomes

<a href="mailto:test@test.com">Email</a>

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

Plunker example here.

陌路终见情 2024-09-23 19:48:57

基于 Daniel Vassallo 的回答,加密 mailto 链接的一种方法可以避免更聪明的垃圾邮件机器人评估 JS document.write(正如 incarnate 所指出的)将解密放入 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

我并不声称知道这是否可以被更复杂的爬虫程序所超越。

Building on Daniel Vassallo's answer, one way to encrypt a mailto link that may avoid 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":

<script>

  function decryptEmail(encoded) {

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

  }

</script>

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

Working Plunker.

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

诗化ㄋ丶相逢 2024-09-23 19:48:57

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

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

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

示例:

[电子邮件受保护]">联系人

替换为

联系人

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

You can use external services like 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.

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. API can be used to hide emails/get URLs dynamically.

Example:

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

Replaced With

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

Will Keep Email Link Working.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文