How to validate entered Email address before sending a mail

Posted by lakhansin-22735 under C# on 6/29/2013 | Points: 10 | Views : 1560 | Status : [Member] | Replies : 4
I want to validate a email address not I mean syntactically but the entered email address is exist or not.

e.g. If I have enter this email address in a textbox 'abc@hotmail.com' system would be give error message 'Mail account is not exist' something like that.

Please suggest anybody.

Thanks in Advance

Lakhan Singh
Tech Lead
BeyondKey System Pvt. Ltd.
Indore, M.P.
India



Responses

Posted by: Satyapriyanayak on: 6/29/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Email_address_exist._Default" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Register"
BackColor="#FF99FF" Font-Bold="True" Width="329px"
onclick="Button1_Click" /><br />
<br />


<br />



<asp:Label ID="Label2" Text="Email" runat="server" BackColor="#FFFF99"
Width="197px" ForeColor="#FF3300"></asp:Label>
<asp:TextBox ID="txtEmail" runat="server" Width="197px"></asp:TextBox>

<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtEmail" ErrorMessage="*Email Required"></asp:RequiredFieldValidator>

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtEmail" ErrorMessage="Insert correct email"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>

<br />



<asp:Label ID="lblMessage" runat="server" BackColor="#FF3300"
ForeColor="Black"></asp:Label>
</div>
</form>
</body>
</html>



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Email_address_exist
{
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
string str = null;

protected void Button1_Click(object sender, EventArgs e)
{
emailcheck();
}
public void emailcheck()
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "select count(*)from employee where email='" + txtEmail.Text + "'";
com = new SqlCommand(str, con);
int count = Convert.ToInt32(com.ExecuteScalar());
con.Close();
if (count > 0)
{
lblMessage.Text = "Sorry! you can't take this email";
}
else
{
lblMessage.Text = "You can take email";
con.Open();
str = "insert into employee(email) values('" + txtEmail.Text + "')";
com = new SqlCommand(str, con);
com.ExecuteNonQuery();
con.Close();

}
}
}
}


If this post helps you mark it as answer
Thanks

lakhansin-22735, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: lakhansin-22735 on: 6/30/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,

Thanks for the response, but what I expect is that the entered email has exist or not

e.g. find out abc@hotmail.com is exist or not at hotmail mail server

Please reply if you have

Thanks,


Lakhan Singh
Tech Lead
BeyondKey System Pvt. Ltd.
Indore, M.P.
India

lakhansin-22735, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj.Trivedi on: 6/30/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello Lakhansin

I beleive that can only be possible and determined by the hotmail server once you send the mail, untill you have the access to their database.

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

lakhansin-22735, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: lakhansin-22735 on: 7/4/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Raj,

Thanks for the response.

Already I have a code by which I can find out the specified email address is exist or not but that code only works for GMAIL not for others.
Here, I require a general code which will be work for any of the mail servers not for specific one.

Lakhan Singh
Tech Lead
BeyondKey System Pvt. Ltd.
Indore, M.P.
India

lakhansin-22735, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response