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

We have all been doing email address validation for a very long time to make sure that the email is correctly formatted. This is to avoid users entering wrongly formatted email address but still they can accidentally give us a wrong email address.

Example of a correctly formatted email address but still wrong:

mailbox.does.not.exist@webdigiapps.com [VALID format but does not exist]

Above case specifically happens when you take important customer email on phone and you type in the wrong email. So is there a QUICK solution to really check the email without sending a test message to the user? Yes.

How to test if the email address actually exists

To check if user entered email mailbox.does.not.exist@webdigiapps.com really exists go through the following in command prompt on windows / terminal on mac. The commands you type in are in green and the server response is in blue. Please refer to MAC & PC screenshots towards the end of this post.

Step 1 – Find mail exchanger or mail server of webdigiapps.com

COMMAND:
nslookup -q=mx webdigiapps.com
RESPONSE:
Non-authoritative answer:
webdigiapps.com mail exchanger = 0 mx2.sub3.homie.mail.dreamhost.com.
webdigiapps.com mail exchanger = 0 mx1.sub3.homie.mail.dreamhost.com.

Step 2 – Now we know the mail server address so let us connect to it. You can connect to one of the exchanger addresses in the response from Step 1.

COMMAND:
telnet mx2.sub3.homie.mail.dreamhost.com 25
RESPONSE:
Connected to mx2.sub3.homie.mail.dreamhost.com.
Escape character is ‘^]’.
220 homiemail-mx7.g.dreamhost.com ESMTP

COMMAND:
helo hi
RESPONSE:
250 homiemail-mx8.g.dreamhost.com

COMMAND:
mail from: <youremail@gmail.com>
RESPONSE:
250 2.1.0 Ok

COMMAND:
rcpt to: <mailbox.does.not.exist@webdigiapps.com>
RESPONSE:
550 5.1.1 <mailbox.does.not.exist@webdigiapps.com>: Recipient address rejected: User unknown in virtual alias table

COMMAND:
quit
RESPONSE:
221 2.0.0 Bye

Screenshots – MAC Terminal & Windows

MAC email verification
Windows email verification

NOTES:

1) the 550 response indicates that the email address is not valid and you have caught a valid but wrong email address. This code can be on the server and called on AJAX when user tabs out of the email field.  The entire check will take less than 2 seconds to run and you can make sure that the email is correct.
2) If email was present the server will respond with a 250 instead of 550
3) There are certain servers with a CATCH ALL email and this means all email address are accepted as valid on their servers (RARE but some servers do have this setting).
4) Please do not use this method to continuously to check for availability of gmail / yahoo / msn accounts etc as this may cause your IP to be added to a blacklist.
5) This is to supplement the standard email address javascript validation.

Also read...

Comments

  1. Pingback: alguna funcion php para verificar existencia de un correo? - Foros de CHW

  2. severin said on :

    Thanks for this useful trick. Unfortunately it does not work with the server I tried. It says:
    554-….
    554 Your access to this mail system has been rejected due to the sending MTA’s p
    oor reputation. If you believe that this failure is in error, please contact the
    intended recipient via alternate means.

    Looks like there’s no workaround?

  3. Amit said on :

    Live demo would be appreciated !

  4. Jasmine said on :

    Wow, these code snippets are really good. I have been looking for a way to check if an email is valid on gmail! This code will be very helpful!

  5. newvalidate said on :

    I get error “Warning: SMTP_validateEmail::require_once(Net_DNS.php) [function.SMTP-validateEmail-require-once]: failed to open stream: No such file or directory in D:\Hosting\4356713\html\smtpvalidateclass.php on line 233

  6. Ousneo said on :

    @newvalidate you have to download NET_DNS class drom PEAR library!!

    I am having my IP reported as spammers !! how to solve this problem ?

  7. Akhilesh thakur said on :

    I understand your code but this command not executed
    nslookup – q=mx reddit.com
    nslookup: couldn’t get address for ‘q=mx’: not found
    please help me

  8. Secret Guy said on :

    For me I encountered a lot of problem to send a resume through internet because of some error flash of my yahoomail so what can i do for this …

  9. ram said on :

    Hi frnds i did not understood how to check, where to keep the email of users want to check var $user if ikeep like this $user=username of email iwant to check

  10. Lp Bell said on :

    I found the perfect tool:
    gives you 5 free validation for an email with the headers!!!!

  11. Boopathi Raja said on :

    Hi All,

    I have a newsletter option which sends nearly 20,000 emails to my customers. I need to check if the email address is exist and active in real time before sending. Can anyone have the code to check this in PHP ? Please help me to resolve this issue

  12. mohan said on :

    Thanks. simple and clear. I want to know is there any restriction to verify email addresses using this SMTP method.

    I want to verify 1 million email addresses. is it possible??

    Thanks in advance

  13. florin said on :

    You could use this application to check thousands of email account on more email addresses you have: bstdownload.com/reviews/valid-email-verifier-1/

  14. Gerold Setz said on :

    Thanks for the snippet.

    I’ll try to extend my service for detecting disposable email addresses (see block-disposable-email.com) with this kind of testing for the real existence of an email address as a second step. Unfortunately services like yahoo are always answering with “250”, so we have to assume that any email address exists there ..

    Gerold

  15. Searock said on :

    Awesome technique !

  16. Pingback: Email validation script - SitePoint Forums

  17. Stephen Adams said on :

    well i am not for sure that there is a web site and this a phone nu.22998933573 they sent me.I am just trying to find out if this a leget place of bussines or a company.

  18. RapidSpeeds said on :

    Very nice guide, presented beautifully and easy to understand.

  19. Clueless said on :

    Sorry for being noobish but is this supposed to work with Windows? nslookup doesn’t understand the first line. There’s an identical question above. This would be a very useful function but the instructions are way, way, way, way, way, over mere mortals heads, assume you know the syntax of everything on any OS and Apollo 11’s LEM computer and mumble RFCs in your sleep. 🙂

  20. Miss Aydan Rifat said on :

    Dont know if there is anything wrong with my email address. If not how is it i cannot locate it and where do i access this. Having roblems cannot subscribe anywhere or receive emails. What am i doing wrong

  21. Bryan said on :

    Is there like a download that can do all that for you

  22. scott said on :

    ok so i took the python code from above and entered into my python idle shell script and got a syntax error??
    COMMAND:
    nslookup – q=mx bigcompanydomain.com

  23. scott said on :

    can i issue these commands thru a macintosh terminal?

  24. Rahul said on :

    Good article. But this assumes that the smtp server runs on port 25 whcih may not be always true. for example, if the mail server uses secure SMTP, the port no will be 465 and we can’t get connection with simple telnet as it is secured.

  25. Pingback: Use PHP To Check Whether Remote URL, Email Or Image Link Exist « DBGLORY 4 YOU

  26. Naidu said on :

    If smtp is running on different port other than default (25), how to check this info? Any way using commands like nslookup?

  27. Omprakash said on :

    This function giving me error while i am exicuting code, the error is

    Warning: Invalid argument supplied for foreach() in C:\wamp\www\Email Validation\smtpvalidateclass.php on line 90

  28. hussain said on :

    my email id has been hacked now password is change how can i recover or delete my email id

  29. Muyeen said on :

    thanks… it was great….

  30. Virgil Bossard said on :

    Hi. Just wanted to leave a quick remark and tell you that I’ve enjoyed viewing your personal site and will be recommending it to my mates. Keep up the good work! Thanks again.

  31. Mehdi said on :

    Very useful. Bundle of Thanks.

  32. Steven Lasch said on :

    In the PHP download, there is the following statements:
    // windows, we need Net_DNS
    require_once ‘Net/DNS.php’;

    Where can I download that include file?

  33. dilip kumar said on :

    hi ,
    i have a question please give the answer if anybody knows about follwing question .

    i wnat to know how can i check the email address present in gmail and facebook in my website?
    i mean email address present in gmail or facebook, from using that emial address , user can login in my website withought registration..

  34. Abeera said on :

    I just love to add it at ysapak.com thanks for sharing it

  35. Scott Seong said on :

    This is a very helpful article, and I did have a chance to modify the script to suit my need. The modified script is available at:

    webtrafficexchange.com/smtp-email-address-validation

    I would like to contribute my change to Google Project, and need your help adding it to the project if you don’t mind.

  36. Bryan said on :

    This doesn’t work with servers that use alternative SMTP ports (465 or 587) and I doubt it works if SSL is required or passwords are required.

  37. Bart said on :

    For the people who are having trouble with the nslookup command line (I see 2 in the comments above): the blogging system has messed up the command line, so don’t just copy/paste it. The actual option in the command line should read `-q=mx`, that is minus sign, “q”, “=”, “mx”, with no spaces in between.

    Also, when trying a nonexistent address in the SMTP server mentioned above, , it replied with “252 send some mail, i’ll try my best”. Well, that’s an interesting response…

    Also: the extra DNS lookup test on the domain name, as added by some commenters, is superfluous: that is part of what the nslookup is for. You’ll now just do 2 DNS lookups instead of one.

  38. Pingback: How to Verify if Email Address Exist or Not

  39. kim said on :

    is there another easy method in finding if an email id exists

  40. Giovanni said on :

    Hi all and thank you for the code. It did really help me out a lot.

    However, I still have a problem on hotmail email address

    I did check it out and enabled SSL on my server, so now it’s working. The problem is that I still get this message back: error 530, could it means authentication required?
    Can you please help me?and give me some avdice?

    I am even thinking of buying it, if someone has a proper working script on PHP o ASP.

    Please write me at pcdevelopers@hotmail.com

    Thank you

  41. Roland said on :

    Great thanks to this usefull utility.
    I have just a comment. If I call the fonction with the following sequence, it doesn’t work.
    $email = ‘foo@gmail.com’;
    $result = $SMTP_Valid->validate($email, $sender);

    To be usable I have added this line in the function setEmails($emails) :
    settype($emails, “array”);

    Any reaction is welcome.

Comments are closed.