ASP

本类阅读TOP10

·asp常用数据库连接方法和技巧
·无组件生成BMP验证码
·一些常用的辅助代码 (网络收藏)
·JavaScript实现的数据表格:冻结列、调整列宽和客户端排序
·VisualStudio.NET_2003及其 MSDN 下载地址
·ASP模拟MVC模式编程
·图片以二进制流输出到网页
·MD5加密算法 ASP版
·ASP.NET编程中的十大技巧
·改进 ASP 的字符串处理性能

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
Email地址有效性验证

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

Email地址有效性的检验是一个经常遇到的问题啦!一般的检验方法是对Email地址字符串进行简单的检验,如是否含有@ .等有效字符等。这种方法只能保证该地址从格式上看似有效,并不能保证地址可达。最近进行大量的地址校验,写了一个小程序,可以保证Email地址真正可达。

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;[email protected]");
   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<IMail 8.02>
HELO
>>250 mail.brookes.com
MAIL FROM:[email protected]
>>250 Ok
RCPT TO:[email protected]
>>250 ok its for [email protected]
DATA
>>ok.send it ;end with <CRLF>.<CRLF>
soem data.
>>250 message queued
QUIT
>>221 Goodbye.




相关文章

相关软件