检查格式正确的电子邮件地址

发布于 2024-07-29 06:19:51 字数 1083 浏览 9 评论 0原文

我有一个这样的电子邮件文本文件:

10:[email protected];[email protected]
12:[email protected]; "George <[email protected]>" 
43:[email protected].;[email protected]
...

我想检查该列表是否包含格式良好的条目。 您知道有什么工具或网络服务可以检查并向我提供无效地址列表吗?

更新 亲爱的大家,感谢您的意见。 我真的在寻找基本的语法检查,所以我会坚持 Rafe 的想法(我会用 Java 来做)。

I have a text file of e-mails like this:

10:[email protected];[email protected]
12:[email protected]; "George <[email protected]>" 
43:[email protected].;[email protected]
...

I want to check whether the list contains well formatted entries. Do you know any tool or web-service to check and give me a list of invalid addresses?

Update Dear all, thank you for your input. I was really looking for a basic syntax check, so I will stay with Rafe's idea (I will do it with Java).

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

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

发布评论

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

评论(5

冬天旳寂寞 2024-08-05 06:19:51

阅读本文,以便您以符合 RFC 的方式进行操作:

http:// /www.eph.co.uk/resources/email-address-length-faq/

Read this so you are doing it the RFC compliant way:

http://www.eph.co.uk/resources/email-address-length-faq/

梦中的蝴蝶 2024-08-05 06:19:51

验证电子邮件的最简单方法可能是向其发送消息。 正如 Sean 指出的那样,这可能会让您容易受到 DoS 攻击,但从您的描述来看,您似乎有一个文本文件而不是网页,所以这应该不是问题。

正则表达式不是匹配电子邮件的好工具,有很多有效地址,天真的匹配会失败。 查看尝试使用正则表达式验证电子邮件的比较,了解详细信息。

如果您必须离线检查它们,我会将电子邮件分成几个部分(即@之前和@之后的部分),然后您可以创建一个自定义验证器(或正则表达式)来验证这些部分。

Probably the simplest way to validate an email is to send a message to it. As Sean points out this can leave you open to DoS attacks, but from your description it seems you have a text file rather than a web page, so this shouldn't be a problem.

Regular expressions are not a good tool for matching emails, there are a lot of valid addresses that naive matching will fail. Check out this comparison of attempts to validate emails with regex for details.

If you have to check them offline, I would split the email into parts (i.e. the parts before the @ and after the @), you could then create a custom validator (or regex) to validate those parts.

清风疏影 2024-08-05 06:19:51

电子邮件验证并不像正则表达式那么简单

首先,我会阅读这篇文章 在阅读 RFC 之前我知道如何验证电子邮件地址

在过去,您只需连接到用户的邮件服务器并使用 VRFY 命令并验证电子邮件地址是否有效,但垃圾邮件发送者滥用了该特权,我们都输了。

现在,我建议采用三部分方法:

  1. 验证语法有效性。 您可以使用 Mail perl 模块 中的怪物正则表达式来检查以确保电子邮件地址格式正确。 然后确保将本地主机域/ip 列入黑名单作为检查的一部分。

  2. 验证域是否有效。 对域进行 DNS 验证检查。 您可以更进一步,使用 STMP 检查并确保您可以连接到该域的有效邮件服务器。 但是,由于虚拟托管方案,可能会出现一些误报结果。

  3. 发送一封实际的电子邮件,但包含链接到服务器上脚本的单个图像。 当电子邮件与图像一起被读取时,您的服务器将收到图像已下载的通知,因此电子邮件是有效的。 然而,现在许多电子邮件客户端默认情况下不会加载图像,因此它不会 100% 有效。

资源

  1. 在 ASP 中验证电子邮件地址(在线)
  2. 在 PHP 中验证电子邮件地址(代码示例)
  3. 此商业产品可进行批量电子邮件验证 ← 这可能就是您正在寻找的
  4. 所以问题:如何在不发送电子邮件的情况下检查电子邮件地址是否存在

Email validation is not as simple as a regular expression

First, I would read this article I Knew How To Validate An Email Address Until I Read The RFC.

Back in the days of yore, you could just connect to the user's mail server and use the VRFY command and verify that an email address was valid, but spammers abused that privilege and we all lost out.

Now, I would recommend a three part approach:

  1. Verify the syntactic validity. You can use the monster regex from the Mail perl module to check to make sure that the email address is well formed. Then make sure to blacklist localhost domains/ips as part of your check.

  2. Verify that the domain is live. Do a DNS validation check on the domain. You could take this one step further and use a STMP check and make sure that you can connect to a valid mailserver for the domain. However, there may be some false negative results due to virtual hosting schemes.

  3. Send an actual email, but include a single image that links to a script on your server. When the email is read with the image, your server will be notified that the image was download and hence the email is alive and valid. However, nowadays many email clients do not load images by default for this very reason, so it won't be 100% effective.

Resources

  1. Validating Email Addresses in ASP (online)
  2. Validating Email Addresses in PHP (code examples)
  3. This commercial product does bulk email verification ← This is probably what you are looking for
  4. SO Question: How to check if an email address exists without sending an-email
不美如何 2024-08-05 06:19:51

我编写了一个简单的 Perl 脚本,它使用 Email::Address 模块来验证这些地址:

#!/usr/bin/env perl

use Email::Address;

while (<>) {
    chomp;
    @addresses = split /\;/;

    foreach my $address (@addresses) {
        if (!Email::Address->parse($address)) {
            print $address, "\n";
        }
    }
}

您只需要安装该模块即可。 其主页是:

http://emailproject.perl.org/wiki/Email::Address

I wrote a simple Perl script that uses the Email::Address module to validate these addresses:

#!/usr/bin/env perl

use Email::Address;

while (<>) {
    chomp;
    @addresses = split /\;/;

    foreach my $address (@addresses) {
        if (!Email::Address->parse($address)) {
            print $address, "\n";
        }
    }
}

You'll just need to install the module. Its home page is:

http://emailproject.perl.org/wiki/Email::Address

终遇你 2024-08-05 06:19:51

这个问题比看起来更难。 面对它时,我从 NMH 中的 mf.c 模块中窃取了代码 来源。 然后,我将地址解析器导入到 Lua 中,这样我就可以从脚本处理电子邮件地址。

使用别人的代码让我免于痛苦。

This problem is harder than it appears. When faced with it, I stole the code from the mf.c module in the NMH sources. I then imported the address parser into Lua so I could handle email addresses from scripts.

Using somebody else's code saved me a world of pain.

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