When collecting email addresses you will always validate it someway often the validation only consists of validating the format of the email address.
Bu what if you wan’t to know if an email address really exits without sending an actual email and ask (which is the absolute best way ofc)
Then you can use the command line with nslookup and telnet.
First thing we need to know what the domains mx-record is if there is any.
nslookup -type=mx dattaproffs.se
dattaproffs.se MX preference = 20, mail exchanger = mail2.dattaproffs.se
dattaproffs.se MX preference = 10, mail exchanger = mail.dattaproffs.se
As you can see dattaproffs.se has two mx-records if the domain of the email you are trying to validate don’t have any mx-records you can stop right here because that domain can’t accept any emails.
If you find a mx you can go on with telnet like this:
telnet mail.dattaproffs.se 25
If there is a mailserver on the other side you will get a response code 220.
220 vsp-inbound-01-02.binero.net ESMTP
Then you can start sending SMTP-commands:
MAIL FROM: firstname.lastname@example.org
250 2.1.0 Ok
RCPT TO: email@example.com
250 2.1.5 Ok
RCPT TO: firstname.lastname@example.org
554 5.7.1 Recipient address rejected: 5.1.1 <email@example.com>: Recipient address rejected: User unknown in virtual mailbox table
221 2.0.0 Bye
The first command must be HELO yourdomain.com or EHLO yourdomain.com the difference between the two is that HELO does not respond with any information about the server which EHLO does.
Then MAIL FROM: firstname.lastname@example.org and you should get a 250 OK
Then RCPT TO: email@example.com if you get a 250 OK here there is a pretty good guess that the email you have is correct and exists. This is not 100% proof of the email existing for example yahoo will always answer 250 OK and only after the DATA command will they tell you if the email address is ok or not. And you do not want to go there because if it exists the recipient will get your test email.
The reason why we test another recipient with RCPT TO: firstname.lastname@example.org is to see if the mail server has catch-all configured. If you get 250 OK on your completely made up address there is a good chance that the server has catch-all and the it’s no way to know if the original email exists either.
The last command is just QUIT.
Validating email addresses with telnet