如何在不向其发送任何内容的情况下检查电子邮件地址是否有效? [英] How do I check if an email address is valid without sending anything to it?

查看:35
本文介绍了如何在不向其发送任何内容的情况下检查电子邮件地址是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户,他有 5000 封来自旧列表的电子邮件,他希望向其推广他的服务.他想知道列表中的哪些电子邮件仍然有效.我想帮他检查一下——不要随机发送 5K 封电子邮件,然后被列为垃圾邮件发送者之类的.想法?

I have a client with 5000 emails from an old list he has that he wants to promote his services to. He wants to know which emails on the list are still valid. I want to check them for him - without sending out 5K emails randomly and then being listed as a spammer or something. Ideas?

推荐答案

bucabay 的 答案是前进的方向.像这样的库本质上所做的是检查指定域(A、MX 或 AAAA)中(邮件)服务器的现有 DNS 记录.之后,它执行所谓的回调验证.这是您连接到邮件服务器的地方,告诉它您想发送到特定的电子邮件地址,然后看看他们是否同意.

bucabay's answer is the way forward. What a library like that essentially does is checking for existing DNS record for (mail) servers at specified domains (A, MX, or AAAA). After that, it do what's termed callback verification. That's where you connect to the mail server, tell it you want to send to a particular email address and see if they say OK.

对于回调验证,您应该注意灰名单服务器对所有内容都说OK",因此如果不实际发送电子邮件,就无法 100% 保证.这是我手动执行此操作时使用的一些代码.这是来自这里的电子邮件地址解析器的补丁.

For callback verification, you should note greylisting servers say OK to everything so there is no 100% guarantee possible without actually sending the emails out. Here's some code I used when I did this manually. It's a patch onto the email address parser from here.

    #
    # Email callback verification
    # Based on http://uk2.php.net/manual/en/function.getmxrr.php
    #

    if (strlen($bits['domain-literal'])){
        $records = array($bits['domain-literal']);
    }elseif (!getmxrr($bits['domain'], $mx_records, $mx_weight)){
        $records = array($bits['domain']);
    }else{
        $mxs = array();

        for ($i = 0; $i < count($mx_records); $i++){
            $mxs[$mx_records[$i]] = $mx_weight[$i];
        }

        asort($mxs);

        $records = array_keys($mxs);
    }

    $user_okay = false;
    for ($j = 0; $j < count($records) && !$user_okay; $j++){
        $fp = @fsockopen($records[$j], 25, $errno, $errstr, 2);
        if($fp){
            $ms_resp = "";

            $ms_resp .= send_command($fp, "HELO ******.com");
            $ms_resp .= send_command($fp, "MAIL FROM:<>");

            $rcpt_text = send_command($fp, "RCPT TO:<" . $email . ">");
            $ms_resp .= $rcpt_text;

            $ms_code = intval(substr($rcpt_text, 0, 3));
            if ($ms_code == 250 || $ms_code == 451){ // Accept all user account on greylisting server
                $user_okay = true;
            }

            $ms_resp .= send_command($fp, "QUIT");

            fclose($fp);
        }
    }

return $user_okay ? 1 : 0;

这篇关于如何在不向其发送任何内容的情况下检查电子邮件地址是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆