How to Check If an Email Address Exists Without Sending an Email

How to check if an email address exists without sending an email?

There are two methods you can sometimes use to determine if a recipient actually exists:

  1. You can connect to the server, and issue a VRFY command. Very few servers support this command, but it is intended for exactly this. If the server responds with a 2.0.0 DSN, the user exists.

    VRFY user
  2. You can issue a RCPT, and see if the mail is rejected.

    MAIL FROM:<>
    RCPT TO:<user@domain>

If the user doesn't exist, you'll get a 5.1.1 DSN. However, just because the email is not rejected, does not mean the user exists. Some server will silently discard requests like this to prevent enumeration of their users. Other servers cannot verify the user and have to accept the message regardless.

There is also an antispam technique called greylisting, which will cause the server to reject the address initially, expecting a real SMTP server would attempt a re-delivery some time later. This will mess up attempts to validate the address.

Honestly, if you're attempting to validate an address the best approach is to use a simple regex to block obviously invalid addresses, and then send an actual email with a link back to your system that will validate the email was received. This also ensures that they user entered their actual email, not a slight typo that happens to belong to somebody else.

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

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;

Is there a way to test if an E-Mail address exists without sending a test mail?

Short answer is no - the only way to validate it exists is to connect to the mail server and send an email to it.

Some more info : Can I check if an email address exists using .net?

"SMTP defines a command for this, but since abuse by spammers totally overwhelmed the number of legitimate uses, virtually every e-mail server in the world is configured to lie."

Another similar question : How to check if an email address exists without sending an email?

How to validate Email for 'valid email' without sending 'email verfication' in laravel 8?

You can't check that entered email address exist, but instead of that can add DNS validation.
Laravel email validation rule uses the egulias/email-validator package with default option RFCValidation. You can add DNSCheckValidation like this.

$request->validate([
'email' => 'required|email:rfc,dns|unique:users'
]);
DNSCheckValidation: Will check if there are DNS records that signal that the server accepts emails. This does not entail that the email exists.


Related Topics



Leave a reply



Submit