Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

How can I check whether the entered email address really exists or not by using asp.net c#?

user-image
Question added by esai mozhi
Date Posted: 2016/03/09
Syed Ali
by Syed Ali , SharePoint Consultant , Exceed IT Services And Training

email address as usually validated at the application's client side. hence, most of the time; they only check for the email address formats...

but to be able to really check for the existence of an email address, you may have to check at the email address' domain if they do exist...

 plus The only way to truly check to see if an email address is valid, is to send an email.

 

protected bool checkDNS(string host, string recType = "MX")

{

    bool result = false;

    try

    {

        using (Process proc = new Process())

        {

            proc.StartInfo.FileName = "nslookup";

            proc.StartInfo.Arguments = string.Format("-type={0} {1}", recType, host);

            proc.StartInfo.CreateNoWindow = true;

            proc.StartInfo.ErrorDialog = false;

            proc.StartInfo.RedirectStandardError = true;

            proc.StartInfo.RedirectStandardOutput = true;

            proc.StartInfo.UseShellExecute = false;

            proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

            proc.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>

                {

                    if ((e.Data != null) && (!result))

                        result = e.Data.StartsWith(host);

                };

            proc.ErrorDataReceived += (object sender, DataReceivedEventArgs e) =>

                {

                    if (e.Data != null)

                    {

                        //read error output here, not sure what for?

                    }

                };

            proc.Start();

            proc.BeginErrorReadLine();

            proc.BeginOutputReadLine();

            proc.WaitForExit(30000); //timeout after 30 seconds.

        }

    }

    catch

    {

        result = false;

    }

    return result;

}

Syed Wahhabuddin Ahmed
by Syed Wahhabuddin Ahmed , IT Project Manager , eTabeb.com - Alawadiliah Information Technology

through rcpt to command server and in C# u can create an object of TCP client and NetworkStream and StreamReader to get response it return code may be in case of not exists.

 

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", );         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:<>" + 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) == )         {             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));     } }

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.