我用vc#做的一个简单的邮箱登陆的程序,邮箱地址 用户名和密码都没有错  邮箱是pop3.163.com(pop.163.com) 点连接后只提示用户名正确 密码却错误(可以肯定密码没有错),哪个高手给指点一下 问题处在什么地方了 ??
运行结果是:
+ok welcome to core mail...........
+ok  core mail......
-err unable to log on
-err command not valid in this state
源代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO;namespace pop3server
{
    public partial class Form1 : Form
    {
        public TcpClient server;
        public NetworkStream netstrm;
        public StreamReader rdstrm;
        public string Data;
        public byte[] szData;
        public string CRLF = "\r\n";
        public Form1()
        {
            InitializeComponent();
        }        private void Form1_Load(object sender, EventArgs e)
        {        }        private void button1_Click(object sender, EventArgs e)
        {
            server = new TcpClient(popadr.Text, 110);//popadr是用户名textbox
            listBox1.Items.Clear();
            try
            {
                netstrm = server.GetStream();
                rdstrm = new StreamReader(server.GetStream());
                listBox1.Items.Add(rdstrm.ReadLine());                Data = "USER" + popadr.Text + CRLF;//popadr是用户名textbox
                szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
                netstrm.Write(szData, 0, szData.Length);
                listBox1.Items.Add(rdstrm.ReadLine());                Data = "PASS" + password.Text + CRLF;
                szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
                netstrm.Write(szData, 0, szData.Length);
                listBox1.Items.Add(rdstrm.ReadLine());                Data = "STAT" + CRLF;
                szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
                netstrm.Write(szData, 0, szData.Length);
                listBox1.Items.Add(rdstrm.ReadLine());            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }        }
    }
}

解决方案 »

  1.   

    网上有很多源码,搜一搜;
    以前有个DEMO,一时找不到;
      

  2.   


    private void button1_Click(object sender, EventArgs e) 
            { 
                server = new TcpClient("pop3.163.com", 110);//popadr是用户名textbox ,这里是服务器名,不是用户名。
                listBox1.Items.Clear(); 
                try 
                { 
                    netstrm = server.GetStream(); 
                    rdstrm = new StreamReader(server.GetStream()); 
                    listBox1.Items.Add(rdstrm.ReadLine());                 Data = "USER" + popadr.Text + CRLF;//popadr是用户名textbox 
                    szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray()); 
                    netstrm.Write(szData, 0, szData.Length); 
                    listBox1.Items.Add(rdstrm.ReadLine());                 Data = "PASS" + password.Text + CRLF; 
                    szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray()); 
                    netstrm.Write(szData, 0, szData.Length); 
                    listBox1.Items.Add(rdstrm.ReadLine());                 Data = "STAT" + CRLF; 
                    szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray()); 
                    netstrm.Write(szData, 0, szData.Length); 
                    listBox1.Items.Add(rdstrm.ReadLine()); 
                } 
                catch(Exception ex) 
                { 
                    MessageBox.Show(ex.ToString()); 
                }         } 
      

  3.   


    private bool isOK()
            {            bool flag = false;
                string userName = this.txtUserName.Text.Trim();
                string passWord = this.txtPassWord.Text.Trim();
                string Data;
                byte[] szData;
                string CRLF = "\r\n";
                string pop = "pop3.163.com";
                TcpClient client = new TcpClient(pop, 110);
                try
                {
                    NetworkStream stream = client.GetStream();
                    StreamReader reader = new StreamReader(stream);
                    Data = "USER" + userName + CRLF;
                    szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
                    stream.Write(szData, 0, szData.Length);                             Data = "PASS" + passWord + CRLF;
                    szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
                    stream.Write(szData, 0, szData.Length);                
                   
                    Data = "STAT" + CRLF;
                    szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
                    stream.Write(szData, 0, szData.Length);                string a = reader.ReadLine();
                    flag = true;            }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);                
                }            return false;
            }
    我写的一份,你参考下,不明白再问