Joy Fernandes

Joy Fernandes

  • NA
  • 4
  • 2.1k

Email Validation

Feb 19 2015 11:33 AM
Sir, i want to do an email validation i.e. i want to check whether and email ID exist or not. I want to check for all the domain such as yahoo, gmail, rediffmail, hotmail, etc. Please send me the solution with the code.

I tried with the following code, but it only works for email.


using System.Net.Sockets;
using System.IO;
using System.Text;public partial class _Default : System.Web.UI.Page
 {
     protected void btnCheck_Click(object sender, EventArgs e)
     {
         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 = BytesFromString("HELO KirtanHere" + CRLF);
         netStream.Write(dataBuffer, 0, dataBuffer.Length);
         ResponseString = reader.ReadLine();
        dataBuffer = BytesFromString("MAIL FROM:<[email protected]>" + 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 = BytesFromString("RCPT TO:<"+TextBox1.Text.Trim()+">"+CRLF);
         netStream.Write(dataBuffer, 0, dataBuffer.Length);
        ResponseString = reader.ReadLine();
         if (GetResponseCode(ResponseString) == 550)
         {
             Response.Write("Mai Address Does not Exist !<br/><br/>");
             Response.Write("<B><font color='red'>Original Error from Smtp Server :</font></b>"+ResponseString);
        }
        /* QUITE CONNECTION */
         dataBuffer = BytesFromString("QUITE" + CRLF);
         netStream.Write(dataBuffer, 0, dataBuffer.Length);
         tClient.Close();
     }
     private byte[] BytesFromString(string str)
     {
         return Encoding.ASCII.GetBytes(str);
     }
    private int GetResponseCode(string ResponseString)
     {
         return int.Parse(ResponseString.Substring(0, 3));
     }

Answers (3)