Search code examples
c#telnet

Check if a email exists with TELNET


basically i have to run in cmd.exe the following commands on C#(if you run it on CMD, it'll work) this link explains better

nslookup -type=mx emailProvider.com //for exemplo nslookup -type=mx hotmail.com.com

after it retun this:

Server:  ip-172-31-0-2.sa-east-1.compute.internal
Address:  172.31.0.2

Non-authoritative answer:
hotmail.com     MX preference = 5, mail exchanger = mx1.hotmail.com
hotmail.com     MX preference = 5, mail exchanger = mx2.hotmail.com
hotmail.com     MX preference = 5, mail exchanger = mx3.hotmail.com
hotmail.com     MX preference = 5, mail exchanger = mx4.hotmail.com

so I take some mail exchanger, for exemplo:

telnet mx1.hotmail.com 25 //port 25

after I nedd write "HELO" for exemplo:

HELO 

so finilly I write :

mail from:<[email protected]>
rcpt to:<[email protected]>//email verificate

so it return a number, 250 or 550, if 250 the email don't exist, else it exists

I tried use the minimalistic Tel net , I tried Process to write lines command windows but nothing of this working, it just work before helo, when I write helo it's don't work but it's working on CMD

some on can help me please?

sorry for my bad english

Thank you!


Solution

  • Good question, POOR solution.

    You are attempting to query the SMTP server to see if an email exists. I highly recommend you don't do this, because your external IP address will end up on a blacklist and you'll be unable to send any mail!

    You don't need to call an external telnet process to communicate with a SMTP server. You can use a TcpClient instance. Examples: this, and this.