| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 899 人关注过本帖
标题:【求助】关于POP3登陆问题
取消只看楼主 加入收藏
zfl313
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2007-8-13
收藏
 问题点数:0 回复次数:3 
【求助】关于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;
       }
搜索更多相关主题的帖子: bool user isReceive port string 
2008-02-12 20:07
zfl313
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2007-8-13
收藏
得分:0 
前面的静态变量和其它的变量
public static int CLOSED = 0;//没有和服如器建立连接时的状态
       public static int CONNECTED = 1;//和pop3服如器建立连接时的状态
       public static int TRANSACTION = 2;//成功登陆smtp后的状态
       public static int FINISHED = 9;//断开连接时的状态
       private TcpClient client;
       private NetworkStream stream;
       private int state = CLOSED;
       private Users username;

梦想开始的地方!
2008-02-12 20:09
zfl313
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2007-8-13
收藏
得分:0 
怎么没人回复

梦想开始的地方!
2008-02-13 15:05
zfl313
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2007-8-13
收藏
得分:0 
大哥大姐们会的给我说一下吧
我好着急啊

梦想开始的地方!
2008-02-13 17:52
快速回复:【求助】关于POP3登陆问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040915 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved