The verification of the validity of email address is a problem often encountered! The general test method is to the email address string for a simple test, such as whether or not to contain the valid characters such as @. This method only guarantees that the address is in a format that appears to be valid and does not guarantee an address to be reached. Recently a large number of address verification, wrote a small program to ensure that the e-mail address is truly up to.
public bool Checkemail (string mailaddress)
{
TcpClient tcpc=new tcpclient ();
try{
String Server=mailaddress.split (' @ ') [1];
Tcpc. Connect (server,25);
NetworkStream S=TCPC. GetStream ();
StreamReader sr=new StreamReader (S,encoding.default);
String Strr= "";
STRR=SR. ReadLine ();
if (!strr.startswith ("the")) return false;
StreamWriter Sw=new StreamWriter (S,encoding.default);
Sw. WriteLine ("HELO");
Sw. Flush ();
STRR=SR. ReadLine ();
if (!strr.startswith (")") return false;
Sw. WriteLine ("MAIL from;brookes@tsinghua.org.cn");
Sw. Flush ();
STRR=SR. ReadLine ();
if (!strr.startswith (")") return false;
Sw. WriteLine ("RCPT to:" +mailaddress);
Sw. Flush ();
STRR=SR. ReadLine ();
if (!strr.startswith (")") return false;
Sw. WriteLine ("QUIT");
Sw. Flush ();
STRR=SR. ReadLine ();
return true;
}catch (Exception ee)
{
return false;
}
}
This program is implemented according to the basic process of SMTP. The basic process for sending mail to a mail server may be this:
Telnet mail.brookes.com 25
>>220 Brookes.com<imail 8.02>
HELO
>>250 mail.brookes.com
MAIL from:brookes@tsinghua.org.cn
>>250 Ok
RCPT to:me@brookes.com
>>250 ok its for me@brookes.com
DATA
>>ok.send it; end With <CRLF>.<CRLF>
Soem data.
>>250 Message Queued
QUIT
>>221 Goodbye.