Email Address validity Verification

Source: Internet
Author: User
Tags flush mail readline valid
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.
&GT;&GT;250 Message Queued
QUIT
>>221 Goodbye.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.