Charles
Charles

Reputation: 221

How do I check if an email address is valid without sending anything to it?

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?

Upvotes: 14

Views: 48534

Answers (6)

gasrios
gasrios

Reputation: 46

It mostly depends on the level of depth with which you want to ensure that an email is valid.

You could stay with sintax validation using a regular expression, but that doesn't really checks for domain or MX records, and many disposable emails will pass that verification.

Many third-party APIs for email validation exist that offer that service. Been using this one for a few months already with the idea of doing a clean-up of my database, and even added it to my sign-up flow, it's worked like a charm.

Upvotes: 0

wesgarrison
wesgarrison

Reputation: 7105

https://github.com/kamilc/email_verifier is a rubygem that will check that the MX record exists and that the SMTP server says the address has a valid mailbox.

Upvotes: 1

KTC
KTC

Reputation: 9003

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.

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;

Upvotes: 7

bucabay
bucabay

Reputation: 5295

You can validate the email via SMTP without sending an actual email.

http://code.google.com/p/php-smtp-email-validation/

You could also send emails out, and check for bounces.

Upvotes: 9

Mike Atlas
Mike Atlas

Reputation: 8231

You'll have to email them at least once.

  • Create a new email list. Send the old list an email with a link they need to click on to continue receiving messages (re-subscribe).
  • Send them all an email and collect all reply-to bounces on a real email account, then purge those bounced emails from your main list.
  • Send them all an HTML email, and one of the images is remotely hosted and requires a unique ID to request it that you set in each email. When your web server returns that image to their client, you can then consider that email as active. This is called a web bug, and will only work if the person automatically loads remote images in their client.

Upvotes: 2

Andrew Hubbs
Andrew Hubbs

Reputation: 9436

I think you need to send the emails to find out. Also, this is pretty much exactly what a spammer is, thus the reason for getting put on spammer lists. Sending in bursts will help you hide this fact though.

Upvotes: 3

Related Questions