bellalau93 2018-11-08 01:46 采纳率: 0%
浏览 975
已结题

c# pop3读取邮件信息时显示连接断开

写一个邮件收发系统,用pop3读取信息
user和password认证显示成功,但是执行STAT或者LIST就报错

报错信息
Exception thrown:'System.IO.IOException' in System.dll
无法将数据写入传输连接:你的主机中的软件已经中断了一个已建立的连接
图片说明

目前试过的方法:关闭防火墙

另外我还写了Networkstream.canwrite判断是否能写,是可以写的,但是运行到写入的句就报错

代码

         private void button10_Click(object sender, EventArgs e)
        {
            //将光标置为等待状态
            Cursor cr = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;

            POPserver = "pop.163.com";
            user = "tayreuier@163.com";
            password = "ihateyou44283968";
            TcpClient receiver = new TcpClient(POPserver, 110);
            Byte[] outbytes;
            string input;

            try
            {
                    nwStream = receiver.GetStream();
                    sr = new StreamReader(nwStream);
                    this.getStatus();
                    string ret;
                    Console.WriteLine(sr.ReadLine());
                    input = "USER" + user + "\r\n";
                    outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
                    nwStream.Write(outbytes, 0, outbytes.Length);
                    this.getStatus();
                    Console.WriteLine(sr.ReadLine());

                    input = "PASS" + password + "\r\n";
                    outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
                    nwStream.Write(outbytes, 0, outbytes.Length);
                    this.getStatus();
                    Console.WriteLine(sr.ReadLine());


                    MessageBox.Show("登陆成功");
                    //listView1.Items.Clear();
                   input = "STAT" + "\r\n";

                  // if(nwStream.CanWrite)
                //{
                    outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
                    nwStream.Write(outbytes, 0, outbytes.Length);
                    textBox10.Text = sr.ReadLine();
               // }
               // else
               // {
              //      MessageBox.Show("无法写入数据");
               // }




                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine("登陆失败");
                }



        }

console的信息

The thread 0x68e0 has exited with code 0 (0x0).
'sendandreceive.vshost.exe' (CLR v4.0.30319: sendandreceive.vshost.exe): Loaded 'D:\engineer program(course design)\sendandreceive\sendandreceive\bin\Debug\sendandreceive.exe'. Symbols loaded.
'sendandreceive.vshost.exe' (CLR v4.0.30319: sendandreceive.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

'sendandreceive.vshost.exe' (CLR v4.0.30319: sendandreceive.vshost.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.resources\v4.0_4.0.0.0_zh-Hans_b77a5c561934e089\System.resources.dll'. Module was built without symbols.
The program '[22668] sendandreceive.vshost.exe' has exited with code -1 (0xffffffff).

  • 写回答

1条回答 默认 最新

  • xiaomad 2018-11-08 02:44
    关注

    你确认前面登陆成功了?console上打出来的返回字符串都没error?
    还有你怎么把密码贴出来了啊,不是真的密码吧/笑哭

    补充一下,我看你代码拼USER之类的命令的时候中间都没加空格啊,能认证成功么?

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名