Click here to Skip to main content
15,916,189 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Could any one tell me, how can I check whether email address is existing or not?
Posted
Updated 5-Jan-16 2:48am
v4
Comments
CPallini 5-Jan-16 8:37am    
What do you mean with 'working'? You have to send an e-mail and then receive the answer back to be sure, you know.
Member 11936584 5-Jan-16 8:44am    
My Question meaning ex: ramu@gmail.com it's existing means id is working, suppose I am given ramu@gmil.com it's not existing, we miss the @gmail.com not a gmail any other mail
Leo Chapiro 5-Jan-16 8:49am    
Do you ask for a regular expression to check the validity of the email address? In this case this is the worst-asked question I ever read!
Member 11936584 5-Jan-16 8:51am    
Regular expression checks only this format xxx@ddd.com. but we are experting xx@gmail.com or xxx@yahoo.com or etc..

The only way is to try sending the email and if you get an undeliverable back then you know it is not valid.
 
Share this answer
 
 
Share this answer
 
Solution in MVC

Create Model Class
C#
public class Email
    {
        public string Name { get; set; }
    }


Create Method
C#
public ActionResult Index()
      {
          return View();
      }


Index view
HTML
@model Email_Valu_MVC.Models.Email
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <div> 
        @using (Html.BeginForm())
        { 
            @Html.Label("Enter Email ID")
            @Html.TextBoxFor(m=>m.Name)
            
            <input type="submit" value="Check" />
        }
   
    </div>
</body>
</html>


Post Method
[HttpPost]
      public ActionResult Index(Email 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 " + CRLF);
          netStream.Write(dataBuffer, 0, dataBuffer.Length);
          ResponseString = reader.ReadLine();
          dataBuffer = BytesFromString("MAIL FROM:<yourgmailidhere@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 = BytesFromString("RCPT TO:<" + e.Name.ToString().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("<font color="red">Original Error from Smtp Server :</font>" + ResponseString);
          }
          /* QUITE CONNECTION */
          Response.Write("Email Id Existing !");
          dataBuffer = BytesFromString("QUITE" + CRLF);
          netStream.Write(dataBuffer, 0, dataBuffer.Length);
          tClient.Close();
          return View();
      }

      private byte[] BytesFromString(string str)
      {
          return Encoding.ASCII.GetBytes(str);
      }
      private int GetResponseCode(string ResponseString)
      {
          return int.Parse(ResponseString.Substring(0, 3));
      }
 
Share this answer
 

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



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