如何检查电子邮件地址是否属于 Gmail

发布于 2024-12-09 14:12:35 字数 246 浏览 0 评论 0原文

我正在创建一个函数,使用 Google 的 API 从某人的 Gmail 帐户导入联系人。不过我知道许多企业注册 Google 是为了拥有更专业的域名(例如 [电子邮件受保护]),但仍然属于到 Gmail。

有办法检查吗?

I'm creating a function uses Google's API to import contacts from a person's gmail account. However I'm aware that many businesses sign up to Google in order to have a more professional domain name( eg. [email protected]) but still belongs to Gmail.

Is there a way to check for that?

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

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

发布评论

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

评论(2

你爱我像她 2024-12-16 14:12:35

选项 1

如果您在 bislr.com 上对 MX 记录进行 DNS 查找,您会得到以下信息:

$ host -t mx bislr.com
bislr.com mail is handled by 10 aspmx.l.google.com.
bislr.com mail is handled by 20 alt1.aspmx.l.google.com.
bislr.com mail is handled by 20 alt2.aspmx.l.google.com.
bislr.com mail is handled by 30 aspmx2.googlemail.com.
bislr.com mail is handled by 30 aspmx3.googlemail.com.
bislr.com mail is handled by 30 aspmx4.googlemail.com.
bislr.com mail is handled by 30 aspmx5.googlemail.com.

托管其电子邮件 Google Apps 的任何人都将拥有与这些记录非常相似的 MX 记录。您可以使用任何常见的 DNS 机制进行 MX 查找,并测试 Google 最推荐的邮件服务器(aspmx.l.google.com、alt1.aspmx.l.google.com 和 alt2.aspmx.l.google)的 MX 记录.com,或查找此列表中的任何/所有服务器。

这不会向您显示任何使用外部转发/过滤服务的人,但它适用于所有常见情况。

选项 2

您可以连接到邮件服务器来验证它是否会接受发送到特定地址的邮件。使用它,我们可以连接到 asmpx.l.google.com 并询问其地址是否是有效的 Google Mail 帐户。

如果您连接到 aspmx.l.google.com:25 并发送此字符串(根据需要替换电子邮件地址):

HELO
MAIL FROM:<[email protected]>
RCPT TO:<[email protected]>

Google 的邮件服务器将使用 smtp 状态代码进行响应,可能是以 250 2.1 等开头的行。 5 如果地址有效,则确定。这是比简单地检查 DNS 记录更干净、更可靠的方法,只要您没有通过使用它向 gmail 发送实际的垃圾邮件而将检查 IP 列入黑名单,就应该有效。

以下是该过程的完整演练。

Option 1

if you do a DNS lookup for the MX records on bislr.com, you get the following:

$ host -t mx bislr.com
bislr.com mail is handled by 10 aspmx.l.google.com.
bislr.com mail is handled by 20 alt1.aspmx.l.google.com.
bislr.com mail is handled by 20 alt2.aspmx.l.google.com.
bislr.com mail is handled by 30 aspmx2.googlemail.com.
bislr.com mail is handled by 30 aspmx3.googlemail.com.
bislr.com mail is handled by 30 aspmx4.googlemail.com.
bislr.com mail is handled by 30 aspmx5.googlemail.com.

Anyone hosting their email Google Apps will have MX records very similar to these. You can do a MX lookup with any common DNS mechanism and test the MX records for Google's most-recommended mail servers - aspmx.l.google.com, alt1.aspmx.l.google.com, and alt2.aspmx.l.google.com, or look for any/all of the servers in this list.

This won't show you anyone who uses an external forwarding/filtering service but it will work for all of the common cases.

Option 2

You can connect to a mail server to verify if it will accept mail to a specific address. Using this, we can connect to asmpx.l.google.com and ask it whether an address is a valid Google Mail account.

If you connect to aspmx.l.google.com:25 and send this string (replace the email addresses as appropriate):

HELO
MAIL FROM:<[email protected]>
RCPT TO:<[email protected]>

Google's mail server will respond with a smtp status code, probably a line starting with something like 250 2.1.5 OK if it's a valid address. This is a cleaner and far more reliable way than simply checking DNS records, and should work as long as you don't get the checking IP blacklisted by using it to send actual spam to gmail.

Here is a full walkthrough of the process.

吃素的狼 2024-12-16 14:12:35

你不能确定。

@lunixbochs 描述的 MX 记录检查涵盖了大多数情况,但许多企业会使用具有不同域名的 Postini。他们还可能使用任意数量的其他邮件预处理引擎来隐藏 aspmx 记录。

另一种检查方法是查看它们是否具有有效域名:

curl http://www.google。 com/a/域名 | grep "domain that isn't using Google Apps"

使用您选择的语言/库而不是curl来获取网址...

You can't be certain.

The MX record check described by @lunixbochs covers most cases, but many corporates will use Postini, which has different domain names. They might also be using any number of other mail pre-processing engines which will hide the aspmx records.

One other way to check is to see if they have an active domain name:

curl http://www.google.com/a/DOMAINNAME | grep "domain that isn't using Google Apps"

Use your language / library of choice instead of curl to fetch the url...

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