Have you ever thought of checking the validity of an email address without sending an email? There are a number of online tools like https://email-checker.net, http://mailtester.com available to check if an email address really exists. There are even paid services for checking email validity. What if you don’t require any tools or paid services for checking the validity of email addresses before you actually send an email? In this tutorial, you will learn how to make use of the command line to check whether a particular email address exists or not, without sending an email. You can make unlimited email validity checks via command line and it won’t cost you a single penny.
You will find these email tools useful if you run a business organization or deals with sending a large number of emails on a day to day life. Many organizations send bulk emails by creating a mailing list/group. The necessary email addresses are added to these groups and bulk mails are send by a single click. You will receive email bounces if the emails are sent to invalid email addresses. To avoid these situations, you can always check the email addresses for validity before adding them to any email groups of mailing lists.
Let’s take a specific email address say “[email protected]” for testing purposes and try to verify if the email address really exists or not. When you send an email to the specified email address “[email protected]”, the sending mail server will look up the MX record for the domain “gmail.com”. We can use dig or nslookup command for DNS lookup to know the mail server details.
dig gmail.com mx
The output should look something like this:
; <<>> DiG 9.10.3-P4-Ubuntu <<>> gmail.com mx
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41105
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;gmail.com. IN MX
;; ANSWER SECTION:
gmail.com. 5 IN MX 20 alt2.gmail-smtp-in.l.google.com.
gmail.com. 5 IN MX 40 alt4.gmail-smtp-in.l.google.com.
gmail.com. 5 IN MX 30 alt3.gmail-smtp-in.l.google.com.
gmail.com. 5 IN MX 10 alt1.gmail-smtp-in.l.google.com.
gmail.com. 5 IN MX 5 gmail-smtp-in.l.google.com.
;; Query time: 59 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Sat Aug 12 12:11:39 IST 2017
;; MSG SIZE rcvd: 150
You can also use nslookup utility to get the mail server details.
nslookup -q=mx gmail.com
The output should look something like this:
Server: 127.0.1.1
Address: 127.0.1.1#53
Non-authoritative answer:
gmail.com mail exchanger = 20 alt2.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 = 30 alt3.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 10 alt1.gmail-smtp-in.l.google.com.
A number of MX records each with different priority values are listed in the DNS lookup for domain “gmail.com”. From the above outputs, we could conclude that mails will be sent via mail server ‘gmail-smtp-in.l.google.com’ since it is assigned higher priority than other mail servers. Please note that smaller the priority value higher is the priority.
Next, we need to connect to the high priority mail server on standard SMTP port 25 to confirm the validity of [email protected]. You can either use telnet or netcat tools to connect to the mail server on the desired port 25.
telnet gmail-smtp-in.l.google.com 25
Trying 74.125.24.27…
Connected to gmail-smtp-in.l.google.com.
Escape character is ‘^]’.
220 mx.google.com ESMTP g130si1474763pfc.186 – gsmtp
Type HELO or EHLO to start the conversation with the Gmail mail server.
HELO gmail.com
250 mx.google.com at your service
Once the conversation has started enter the sender email address using ‘mail from’. Here I am using our test email account “[email protected]” for sender address. Replace the specified test email address with your email address.
mail from:<[email protected]>
250 2.1.0 OK x13si1491813pfi.574 – gsmtp
If the server responds with “250 OK” then we can proceed to the next step. Enter the recipient email address using ‘rcpt to’. Replace the test email address with your recipient email address.
rcpt to:<[email protected]>
250 2.1.5 OK x13si1491813pfi.574 – gsmtp
The recipient email address is valid if the server responds with “250 OK”. You should get a server response of “550” as shown below if the recipient email address does not exist.
rcpt to:<[email protected]>
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 t3si1541957pfl.88 – gsmtp
That’s it! This is how you check whether an email address really exists via command line. I hope you have found this tutorial useful.
If you need any further help please do reach our support department.