最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Email地址有效性验证
时间:2008-01-12 编辑:简简单单 来源:一聚教程网
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("220")) return false;
StreamWriter sw=new StreamWriter(s,Encoding.Default);
sw.WriteLine("HELO");
sw.Flush();
strR=sr.ReadLine();
if(!strR.StartsWith("250")) return false;
sw.WriteLine("MAIL FROM;brookes@tsinghua.org.cn");
sw.Flush();
strR=sr.ReadLine();
if(!strR.StartsWith("250")) return false;
sw.WriteLine("RCPT TO:"+mailAddress);
sw.Flush();
strR=sr.ReadLine();
if(!strR.StartsWith("250")) return false;
sw.WriteLine("QUIT");
sw.Flush();
strR=sr.ReadLine();
return true;
}catch(Exception ee)
{
return false;
}
}
这个程序是根据SMTP的基本过程实现的。与一个mail服务器连接发邮件的基本过程可能是这样的:
telnet mail.brookes.com 25
>>220 brookes.com
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
soem data.
>>250 message queued
QUIT
>>221 Goodbye.
-
上一个: URL编码与SQL注射
-
下一个: ASP开发规范.doc
相关文章
- VBS 批量Ping的项目讲解 09-19
- 如何封装一个Ajax函数介绍 09-16
- ASP实现加法验证码方法 09-16
- ASP错误捕获的几种常规处理方法介绍 09-16
- ajax实现城市三级联动的代码介绍 09-16
- asp中获取日期为星期几的技巧 09-14