用C#电子邮件验证的类
来源:网络整理 责任编辑:栏目编辑 发表时间:2013-07-02 03:38 点击:次
/*
电子邮件验证
Windows2000 、Microsoft.NET Beta2、C#
Made By Qingming Zhao
Email: zqm2000@126.com
2002,2,17
csc /target:library ValideEmail.cs
*/
using System;
using System.Net.Sockets;
using System.IO;
using System.Text;
namespace BysWangZhan
{
class ValidateEmail //电子邮件验证
{
public string strEmail;
public string strServer;
public int intPort;
string Email
{
set
{
strEmail=value;
}
get
{
return strEmail;
}
}
string Server
{
set
{
strServer=value;
}
get
{
return strServer;
}
}
int Port
{
set
{
intPort=value;
}
get
{
return intPort;
}
}
/* static void Main(string[] args)
{
ValidateEmail MyTest=new ValidateEmail();
MyTest.Email="zqm446@octopus.cdut.edu.cn";
MyTest.Server="octopus.cdut.edu.cn";
MyTest.Port=25; //默认端口是25
Console.WriteLine(MyTest.Exists());
}
*/ public bool Exists()
{
TcpClient tcpc = new TcpClient();
tcpc.Connect(strServer,intPort);
StreamReader sr1 = new StreamReader(tcpc.GetStream(),Encoding.Default);
sr1.ReadLine();
if(OperaStream(tcpc,"HELO "+strServer) != "250")
{
OperaStream(tcpc,"QUIT");
return false;
}
if(OperaStream(tcpc,"MAIL FROM: my@my.com") != "250")
{
OperaStream(tcpc,"QUIT");
return false;
}
if(OperaStream(tcpc,"RCPT TO: "+strEmail) != "250")
{
OperaStream(tcpc,"QUIT");
return false;
}
else
{
OperaStream(tcpc,"QUIT");
return true;
}
}
static string OperaStream(TcpClient tcpc,string strCmd)
{
Stream TcpStream;
strCmd = strCmd + "rn"; //加入换行符
TcpStream = tcpc.GetStream();
byte[] bWrite = Encoding.Default.GetBytes(strCmd.ToCharArray());
TcpStream.Write(bWrite,0,bWrite.Length);
StreamReader sr = new StreamReader(tcpc.GetStream(),Encoding.Default);
string rl = sr.ReadLine();
string sp = rl.Substring(0,3);
return sp;
}
}
}
电子邮件验证
Windows2000 、Microsoft.NET Beta2、C#
Made By Qingming Zhao
Email: zqm2000@126.com
2002,2,17
csc /target:library ValideEmail.cs
*/
using System;
using System.Net.Sockets;
using System.IO;
using System.Text;
namespace BysWangZhan
{
class ValidateEmail //电子邮件验证
{
public string strEmail;
public string strServer;
public int intPort;
string Email
{
set
{
strEmail=value;
}
get
{
return strEmail;
}
}
string Server
{
set
{
strServer=value;
}
get
{
return strServer;
}
}
int Port
{
set
{
intPort=value;
}
get
{
return intPort;
}
}
/* static void Main(string[] args)
{
ValidateEmail MyTest=new ValidateEmail();
MyTest.Email="zqm446@octopus.cdut.edu.cn";
MyTest.Server="octopus.cdut.edu.cn";
MyTest.Port=25; //默认端口是25
Console.WriteLine(MyTest.Exists());
}
*/ public bool Exists()
{
TcpClient tcpc = new TcpClient();
tcpc.Connect(strServer,intPort);
StreamReader sr1 = new StreamReader(tcpc.GetStream(),Encoding.Default);
sr1.ReadLine();
if(OperaStream(tcpc,"HELO "+strServer) != "250")
{
OperaStream(tcpc,"QUIT");
return false;
}
if(OperaStream(tcpc,"MAIL FROM: my@my.com") != "250")
{
OperaStream(tcpc,"QUIT");
return false;
}
if(OperaStream(tcpc,"RCPT TO: "+strEmail) != "250")
{
OperaStream(tcpc,"QUIT");
return false;
}
else
{
OperaStream(tcpc,"QUIT");
return true;
}
}
static string OperaStream(TcpClient tcpc,string strCmd)
{
Stream TcpStream;
strCmd = strCmd + "rn"; //加入换行符
TcpStream = tcpc.GetStream();
byte[] bWrite = Encoding.Default.GetBytes(strCmd.ToCharArray());
TcpStream.Write(bWrite,0,bWrite.Length);
StreamReader sr = new StreamReader(tcpc.GetStream(),Encoding.Default);
string rl = sr.ReadLine();
string sp = rl.Substring(0,3);
return sp;
}
}
}
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>