【求助】关于POP3登陆问题
我写的代码怎么检测不到pop3验证用户密码时返回的+OK高手帮我改一下用telnet时密码是对的能返回+OK以下是代码
//建立tcp连接
public bool Connect(Users user, bool isReceive, ref string msg)//isReceive为真时连接pop3假时连接smtp
{
this.username = user;
bool connected = false;
string server, port, name, psw;
if (isReceive)
{
server = user.InServerAdd;
port =Convert .ToString( user.InServerPort);
name = user.UserName;
psw = user.UserPwd;
}
else
{
server = user.OutServerAdd;
port = Convert .ToString(user.OutServerPort);
}
if (server=="")
{
msg = "服务器地址无效!";
}
if (port =="")
{
if (isReceive)
{
port ="110";
}
else
{
port ="25";
}
}
client =new TcpClient (server ,Convert .ToInt32(port));
stream =client .GetStream();
string response=ReceiveResponse();
if((response.IndexOf ("OK")>=0||(response .IndexOf ("220")>=0)))
{
connected =true ;
state=CONNECTED ;
if((!isReceive))
{
state =TRANSACTION ;
}
}
msg="已和服务器建立了连接";
return connected ;
}
//接受服务器返回的信息
public string ReceiveResponse()
{
byte[] bb=new byte [512];
try
{
int len = stream.Read(bb,0,bb.Length);
string read = Encoding.UTF8.GetString(bb);
return read.Substring(0,len );
}
catch(Exception e)
{
return e.ToString();
}
}
//发送命令
public void SendCommand(string command)
{
try
{
string send = command+"\r\t";
byte[] arrsend = Encoding.Default.GetBytes(send.ToCharArray());
stream.Write(arrsend, 0, arrsend.Length);
}
catch (Exception e)
{
}
}
//登陆pop3
public bool LoginPOP(ref string msg)
{
string res;
if (state != CONNECTED)
{
msg = "还没建立连接!";
return false;
}
SendCommand("user " + this.username.UserName);
res=ReceiveResponse();
if(res.IndexOf ("OK")<0)
{
msg ="用户名验证错误!";
return false;
}
SendCommand("pass " + this.username .UserPwd );
res=ReceiveResponse ();
if(res.IndexOf ("OK")<0)
{
msg="密码验证错误!";
return false ;
}
msg = "登陆pop3服务器成功!";
state = TRANSACTION;
return true;
}