Our team always face email existence problem when they try to:
- Verify the registered account holder’s email id or
- While sending mail to anonymous user who posted comment with some fake email id or
- To check, if that email address is still valid (ex: 2 years back emailed was valid but not now)
Well it’s not possible to know 100% whether given e-mail address exists in real or not but it will be handy in majority of the cases. You can do it manually also if you are in Linux box using host or nslookup and telnet command. I would prefer host command for this purpose.
How it works:
- Check if domain name exists or not using ping command
- If domain name exists then check if it has any mail handlers i.e. mx records in DNS. Use host or nslookup command for it
- If mx record exists for that domain name use that mail handler using telnet command
- Use telnet and smtp command to verify user email id. If you get 250/Ok for user email id. You may assume that it exists.
Here many things came into the picture while testing various mail ids from various mail handlers. I will discuss it under “possible ways of failures”
Steps to check the email existence manually
1. Get the mail id to verify (we can get domain-name from this format to use it in our next step userid@domain-name . For ex:firstname.lastname@example.org)
2. Either use nslookup command or host command to get mail server address (Lists of mx records from DNS)
a. Using nslookup:
nslookup –type=mx domain-name
b. Using host :
host –t mx domain-name
3. Get the least digital value’s mx record to use it in telnet
a. telnet mxrecord port-no i.e. telnet mail.aliencoders.org 25
b. Once connected use SMTP commands to know if email id exists or not. It will return 250 as a return code with OK or Accepted. Depending upon mail server configuration and Linux flavors too.
Let’s see it practically with all combination of commands, inputs and outputs 😀
Output from nslookup (it will show many more things which I have not shown here)
$ nslookup -type=mx gmail.com
gmail.com mail exchanger = 20 alt2.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 30 alt3.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 40 alt4.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 5 gmail-smtp-in-v4v6.l.google.com.
gmail.com mail exchanger = 10 alt1.gmail-smtp-in.l.google.com.
Output from host command ( I prefer this over nslookup )
$ host -t mx gmail.com
gmail.com mail is handled by 30 alt3.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 40 alt4.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 5 gmail-smtp-in-v4v6.l.google.com.
gmail.com mail is handled by 10 alt1.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 20 alt2.gmail-smtp-in.l.google.com.
Get the value which has lowest ranked digit. In this case it is 5 so take gmail-smtp-in-v4v6.l.google.com for our purpose
Either use host or nslookup for the first stage.
telnet gmail-smtp-in-v4v6.l.google.com 25
Connected to gmail-smtp-in-v4v6.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP hk4si16050652obc.168
Step 2 (type helo, if it didn’t work try helo hi, if it didn’t work too try ehlo then )
250 mx.google.com at your service
Step 3 (type any valid email id. Invalid email id will say ok but after rcpt to it will throw an error and don’t skip this step)
mail from: <email@example.com>
250 2.1.0 OK hk4si16050652obc.168
Step 4 (You need to provide email which needs to be verified. Ok means it may exists. Not 1005 guaranteed on existence but we can infer that this email id may work)
rcpt to: <firstname.lastname@example.org>
250 2.1.5 OK hk4si16050652obc.168
Telnet outputs on failure (Various reasons are there)
1. Network is unreachable. (sometimes it is reachable form one host but not from others)
telnet gmail-smtp-in-v4v6.l.google.com 25
telnet: connect to address 126.96.36.199: Connection timed out
telnet: connect to address 2001:4860:8005::1b: Network is unreachable
telnet: Unable to connect to remote host: Network is unreachable
2. Error at mail from:<mail-id> :
- Don’t forget to use <> while typing email id. email@example.com is wrong. firstname.lastname@example.org is correct
- Never use space before or after mail id
- Don’t use single quote or double quote while typing email id
3. If email id exists but it doesn’t show up 250/ok then below reasons may justify this:
- Server response delayed
- Email address black listed
- Email does not exist (even if it existed 2 years back )
Steps to check email existence using Perl
- Get Mail::CheckUser module from CPAN
- Install it either manually or using cpan command
- Write simple script using this module and check the output
Good thing with this script is:
- You don’t need to use any command like host, nslookup telnet and don’t need to remember all those SMTP commands.
- Just pass the email id rest thing it will do.
- Internally it checks:
- It checks the syntax of an email address.
- It checks if there any MX records or A records for the domain part of the email address.
- It tries to connect to an email server directly via SMTP to check if mailbox is valid. It can detect bad mailboxes in many cases.
Why still this trick doesn’t assure 100% proof that email id exists or not?
There can be many reasons for not trusting on this script or the above said manual steps. Best way is to send an email to the given email id. If it bounced back, means it doesn’t exist or can’t be delivered. (I chat with a person in gtalk but can’t send an email to that person. Strange isn’t it).
- There may be server delay
- Email id may be black listed
- It may say it exists if it has to bypass proxies
- Final output will depend upon server settings which may be using an algorithm to stop spammer like stuffs
- For instance SMTP defines the VRFY command for this purpose but gmail doesn’t support it.
- Never send bulk emails, your mail id will be flagged as a spammers by many hosting companies
- You may not get proper result because network is unreachable or down by that time
Note: This was just for educational purpose and found helpful for web masters or admins. Don’t use it as spam stuffs, you IP address and your mail id will be blacklisted. Like email@example.com has been blacklisted from various mail servers.Read more