我们可以在asp.net中使用正则表达式验证电子邮件地址。现在,我们怎样才能发现电子邮件地址确实存在?
例如,farzaneh@yahoo.com
具有正确的电子邮件格式,但不存在。
此代码仅适用于gmail帐户:
protected void Button1_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 HELLO to SMTP Server and get Response */
dataBuffer = BytesFromString("HELO " + CRLF);
netStream.Write(dataBuffer, 0, dataBuffer.Length);
ResponseString = reader.ReadLine();
dataBuffer = BytesFromString("MAIL FROM:<hosseinhagh66@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:<" + TextBox1.Text.Trim() + ">" + CRLF);
netStream.Write(dataBuffer, 0, dataBuffer.Length);
ResponseString = reader.ReadLine();
if (GetResponseCode(ResponseString) == 550)
{
Response.Write("Mai Address Does not Exist !");
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));
}
有什么方法可以知道吗?
感谢。
答案 0 :(得分:7)
简短的回答是:您无法验证是否存在电子邮件地址,而无需正在验证其地址的用户的帮助。
实现此目的的事实标准是发送验证电子邮件,其中包含生成的一次性链接,供用户遵循以确认收到发送到该地址的电子邮件