In this article, I will show you how to verify email existence via command-line. I mean you can do it manually without sending actually email just to verify its existence.
Verify email existence via command-line
In facts, this is a pretty old tip, and it is still working today.
There are three steps to do it:
1. Locate or find mail servers of target domain, that is, the domain part of the email address you want to verify.
2. Telnet into the mail server to confirm if server is connectable and working.
3. Send commands into mail server to verify email existence.
Okay, let’s do this.
Step 1: Locate mail servers
In other words, this is to find MX records of the domain in DNS zone file. If the target domain is serving such email address then it must been served from a mail exchange server, and MX records should be configured to define how to handle in/out emails.
To find MX records, perform this command:
$ nslookup -q=mx DOMAIN_NAME
It will display one or several mail servers. We will access one of those mail servers to do the verification.
Let say, we want to verify an email named like
email@example.com. Then we need to do MX lookup with
gmail.com. So the lookup command will be:
$ nslookup -q=mx gmail.com Non-authoritative answer: 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.l.google.com. gmail.com mail exchanger = 10 alt1.gmail-smtp-in.l.google.com.
Your results might differ from me, but we can just access one of those Google mail servers to do the job.
I have written a detail tutorial on MX lookup using command-line. Check it out if you want to know more about it.
Step 2: Telnet into mail server
The purpose is to:
- verify if mail server is working or not.
- to perform email existence verification.
And to do that, we will use
telnet utility. You might want to install it if it’s not available on your computer, then proceed the command.
$ telnet MAIL_SERVER MAIL_PORT
There are two parameters for the command:
- MAIL_SERVER : is the MX records we locate on step 1 previously.
- MAIL_PORT : is the port to access mail exchange server. By default, it is 25.
So, let’s take one of the above google mail servers, and telnet into it.
$ telnet gmail-smtp-in.l.google.com 25 Trying 220.127.116.11... Connected to gmail-smtp-in.l.google.com. Escape character is '^]'. 220 mx.google.com ESMTP c76si9719600pga.70 - gsmtp
If it works then you should be inside the telnet shell of that server, from here you can send commands to request actions.
Step 3: Send commands to verify email existence
At the moment, you should be inside telnet prompt that has access to MX server. If not, try step 2 again.
Try following actions:
telnet gmail-smtp-in.l.google.com 25 Trying 18.104.22.168... Connected to gmail-smtp-in.l.google.com. Escape character is '^]'. 220 mx.google.com ESMTP o1si1949138pld.79 - gsmtp EHLO Buddy 250-mx.google.com at your service, [22.214.171.124] 250-SIZE 157286400 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 MAIL FROM: <firstname.lastname@example.org> 250 2.1.0 OK o1si1949138pld.79 - gsmtp RCPT TO: <email@example.com> 250 2.1.5 OK o1si1949138pld.79 - gsmtp QUIT 221 2.0.0 closing connection o1si1949138pld.79 - gsmtp Connection closed by foreign host.
The very first command we need to send is
HELO command. This is to initialize the communication between telnet and mail servers. Actually, it is to communicate with SMTP to send mail. It will response with a list of available commands for SMTP communication.
The next command is to specify the sender’s email address, that is
MAIL FROM. You can put in any email address.
Now, the important command of our goal,
RCPT TO, this is to specify the receiver’s email address, and we should type in the email we want to verify on this mail servers. In above example, I typed in
RCPT TO: <firstname.lastname@example.org>, and it responses with
250 OK, it means that email exists on Gmail server.
And if email doesn’t exist on MX servers, something like below will display:
RCPT TO: <email@example.com> 550-5.1.1 The email account that you tried to reach does not exist. Please try 550-5.1.1 double-checking the recipient's email address for typos or 550-5.1.1 unnecessary spaces. Learn more at 550 5.1.1 https://support.google.com/mail/?p=NoSuchUser r2si12452388pgk.389 - gsmtp
Look at the description, it is very descriptive response from Gmail server. However, for other mail servers, it might not be clear like this. But you will know whether the email exists or not by looking at the response code, 550.
While issuing commands to mail servers via telnet, you just need to confirm the response code.
- 250 : on succeed.
- 550 : if fail.
Several points you need to be aware.
- Verifying email existence in this method generally works in most of the case. But some mail servers is configured to accept any email in
- Don’t try to do this often, your IP might be put into blacklist. Especially, when you try to automate this process via code.
As I said, it is very easy to verify email existence, anyone can perform it using command-line. Following exact steps in this tutorial, you get it done.
However, if you’re a developer, you can try to automate it via some scripts if needed.
If you think this is too complicated, then you can verify email existence just by sending a test email to the target email address. You will receive a notification email if it doesn’t exist.