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.
1 2 3 4 5 |
nslookup -type=mx dattaproffs.se Non-authoritative answer: 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:
1 |
telnet mail.dattaproffs.se 25 |
If there is a mailserver on the other side you will get a response code 220.
1 |
220 vsp-inbound-01-02.binero.net ESMTP |
Then you can start sending SMTP-commands:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
EHLO dattaproffs.se 250-PIPELINING 250-SIZE 104857600 250-STARTTLS 250-ENHANCEDSTATUSCODES 250 8BITMIME MAIL FROM: fredrik@dattaproffs.se 250 2.1.0 Ok RCPT TO: fredrik@dattaproffs.se 250 2.1.5 Ok RCPT TO: asdfasdfsadfsadgfdgdfvb@dattaproffs.se 554 5.7.1 Recipient address rejected: 5.1.1 <asdfasdfsadfsadgfdgdfvb@dattaproffs.se>: Recipient address rejected: User unknown in virtual mailbox table QUIT 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: name@yourdomain.com and you should get a 250 OK
Then RCPT TO: theemail@youwanttotest.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: somejibberishxxzxnnzx@somedomain.com 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.