C# .NET - To check whether an email id exists or not

Asked By abinav shankar on 19-Jun-12 01:20 AM
I want to check whether a given email exists or not using .net
i have reffered some codes but most of it leading to some online tools is there any other way of achieving it?
Jitendra Faye replied to abinav shankar on 19-Jun-12 01:29 AM

you can do this by using this code-


protected void btnCheck_Click(object sender, EventArgs e)
{

if (TxtEmail.Text )

{

SqlConnection con = new SqlConnection("con string");

SqlDataAdapter da;

string mySQL = "SELECT * FROM tablename where email='" + TxtEmail.Text + "'";

da = new SqlDataAdapter(mySQL, con);

con.Open();

DataSet ds = new DataSet();

da.Fill(ds);

if (ds.Tables[0].Rows.Count > 0)

{

   //Exist

}

else

{

   //Not Exist

}

}

USE THIS CODE AND LET ME KNOW.

TSN ... replied to abinav shankar on 19-Jun-12 02:05 AM

hi..

Inorder to validate an email exists in the real world or Not , then there is only possible solution is just when ever a user registers on to the site, just send a welcome mail and mail to confirm the registration.

 

So its better to send a mail to the registered email id on registering.

 

 

For sending email in .net we can use SmtpClient

dipa ahuja replied to abinav shankar on 19-Jun-12 03:32 AM
Check this code:
 
private void buttonX1_Click(object sender, EventArgs e)
{
  
  if (!checkExist(textBox1.Text.ToString()))
  {
    MessageBox.Show("User Already Exist!");
    textBox1.Focus();
    return;
  }
  //insert query code        
}
public bool checkExist(string s)
{
  SqlDataAdapter da = new SqlDataAdapter("Select uname from table where uname='"
    + s + "'", "ConnectionString");
 
  DataTable dt = new DataTable();
  da.Fill(dt);
 
  if (dt.Rows.Count > 0)
  {
    return false;
  }
  else
  {
    return true;
  }
}