Click here to Skip to main content
15,888,287 members
Please Sign up or sign in to vote.
1.07/5 (4 votes)
Hi,

How to check whether any "Email" Exists or not.
Is there any classes(in c#) providing this service.

Thanks in Advance............,


Regards
Satish Kumar
Posted
Comments
Kiran Susarla 12-Feb-13 5:40am    
Where do you want to check? Is it in Microsoft Exchange Server (in Outlook Client) or in any Internet mails (such as gmail, yahoo mail or Hotmail)?
_Amy 12-Feb-13 6:52am    
Which email? Where you want to check? What kind of classes do you need to check that? Improve your question with all the informations, so that we can able to understand your question.
[no name] 12-Feb-13 7:30am    
want to check from your database or else ? please post
govindsharma871 30-Jan-15 1:25am    
On Internet mails (such as gmail, yahoo mail or Hotmail)?
Sublarton0 2-May-16 4:03am    
You did not specify if you're referring to email message or email account, this makes a huge difference.
- For an account you can check Solution 2.
- For a message you can check this C# component for emails, what you can do is retrieve all emails with IMAP in C# and then search for the targeted one.

 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 31-Dec-15 11:51am    
Maciej,

It's fair enough, so I up-voted it, but it leaves the question unanswered, because it does not suggest what answer you consider correct; some might be wrong. That's why I posted Solution 6, to try to make it certain; please see.

Best wishes in New Year!

—SA
Maciej Los 4-Jan-16 2:19am    
Thank you, Sergey.
All the Best for you and Your Family on 2016!
Sergey Alexandrovich Kryukov 4-Jan-16 12:25pm    
Thank you, Maciej.
You and your family, too!
—SA
Generally, there is no a way to check up existence of some e-mail account except sending some e-mail and getting the answer, which you, naturally, may never get, even if the account exists. This is not how mail system works.

And thing about this: it would be very insecure, would invite spam.

For more detail, please read on e-mail tracking: Email tracking - Wikipedia, the free encyclopedia[^].

You cannot rely on any of the tracking techniques, when it comes to arbitrary e-mail address. Non of them can be guaranteed to supported. I would assume it could be only useful inside a big corporation with unified technical policies.

Best wishes in New Year!

—SA
 
Share this answer
 
v2
Comments
Afzaal Ahmad Zeeshan 31-Dec-15 12:26pm    
Happy new year Sergey!

4ed. I can vote a 5 if you can add that a good way to check if email exists is to send a verification code to it so that user confirms it! Just the way Facebook and Google does that. :-)
Sergey Alexandrovich Kryukov 31-Dec-15 12:35pm    
Thank you, Afzaal. Happy New Year!

I thought that "verification code" approach is covered by the Wikipedia article I referenced. Anyway, this method cannot be relied on. I don't think this is what the inquirer asks about, but there the other parties have no obligations of handling this verification code.

—SA
Afzaal Ahmad Zeeshan 31-Dec-15 12:41pm    
Sure.
Maciej Los 4-Jan-16 2:19am    
5ed!
Sergey Alexandrovich Kryukov 4-Jan-16 12:26pm    
Thank you, Maciej.
—SA
You can check the syntax of the email with such regular expression:

C#
public static bool isEmail(string inputEmail)
{
   inputEmail  = NulltoString(inputEmail);
   string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
         @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
         @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
   Regex re = new Regex(strRegex);
   if (re.IsMatch(inputEmail))
    return (true);
   else
    return (false);
}


Or you can make SMTP check:

C#
string[] host = (address.Split('@'));
string hostname = host[1];

IPHostEntry IPhst = Dns.Resolve(hostname);
IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
Socket s= new Socket(endPt.AddressFamily, 
        SocketType.Stream,ProtocolType.Tcp);
s.Connect(endPt);


The following snippets are not mine, they are taken from this source:
http://stackoverflow.com/questions/3883518/can-i-check-if-an-email-address-exists-using-net[^]
 
Share this answer
 
Write a module and this module on form load or any other button click

TcpClient tClient = new TcpClient("gmail-smtp-in.l.google.com", 25);
string CRLF = "\r\n";
byte[] dataBuffer;
string ResponseString;
NetworkStream netStream = tClient.GetStream();
StreamReader reader = new StreamReader(netStream);
ResponseString = reader.ReadLine();
/* Perform HELO to SMTP Server and get Response */
dataBuffer = Encoding.ASCII.GetBytes("HELO KirtanHere" + CRLF);
netStream.Write(dataBuffer, 0, dataBuffer.Length);
ResponseString = reader.ReadLine();
dataBuffer = Encoding.ASCII.GetBytes("MAIL FROM:<youremail@gmail.com>" + CRLF);
netStream.Write(dataBuffer, 0, dataBuffer.Length);
ResponseString = reader.ReadLine();
/* Read Response of the RCPT TO Message to know from google if it exist or not */
dataBuffer = Encoding.ASCII.GetBytes("RCPT TO:<senderemail@domainname.com>" + CRLF);
netStream.Write(dataBuffer, 0, dataBuffer.Length);
ResponseString = reader.ReadLine();
if (GetResponseCode(ResponseString) == 550)
{
MessageBox.show("Mai Address Does not Exist !

Original Error from Smtp Server :" + ResponseString);

}
/* QUITE CONNECTION */
dataBuffer = BytesFromString("QUITE" + CRLF);
netStream.Write(dataBuffer, 0, dataBuffer.Length);
tClient.Close();

// write a sub procedure for return status of email which is valid or not
private int GetResponseCode(string ResponseString)
{
return int.Parse(ResponseString.Substring(0, 3));
}
 
Share this answer
 
Comments
Member 13461780 10-Nov-17 12:28pm    
it is not working when i used with vb.net

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900