C# 检索命令不';当尝试从pop3 C访问邮件时,似乎不起作用#

C# 检索命令不';当尝试从pop3 C访问邮件时,似乎不起作用#,c#,pop3,C#,Pop3,当我连接到pop3.live.com时,连接是正常的,它还会显示我的消息量和文件大小,但当我尝试使用“RETR”获取消息并在控制台应用程序上显示它们时,不会显示任何内容 这是我到目前为止所拥有的 string str = string.Empty; string strTemp = string.Empty; using (TcpClient tc = new TcpClient()) {

当我连接到pop3.live.com时,连接是正常的,它还会显示我的消息量和文件大小,但当我尝试使用“RETR”获取消息并在控制台应用程序上显示它们时,不会显示任何内容

这是我到目前为止所拥有的

 string str = string.Empty;
            string strTemp = string.Empty;
            using (TcpClient tc = new TcpClient())
            {
                tc.Connect("pop3.live.com", 995);
                using (SslStream sl = new SslStream(tc.GetStream()))
                {
                    sl.AuthenticateAsClient("pop3.live.com");
                    using (StreamReader sr = new StreamReader(sl))
                    {
                        using (StreamWriter sw = new StreamWriter(sl))
                        {
                            sw.WriteLine("USER " + _username);
                            sw.Flush();
                            sw.WriteLine("PASS "+ _password);
                            sw.Flush();
                            sw.WriteLine("LIST");
                            sw.Flush();
                            sw.WriteLine("RETR");
                            sw.Flush();
                            sw.WriteLine("QUIT ");
                            sw.Flush();

                            while ((strTemp = sr.ReadLine()) != null)
                            {
                                if (strTemp == "." || strTemp.IndexOf("-ERR") != -1)
                                {
                                    break;
                                }
                                str += strTemp;
                            }
                        }
                    }
                }
            }
            Console.WriteLine(str);
            Console.ReadLine();

使用
RETR
,您需要指定要检索的消息<不支持没有编号的code>RETR。

首先,您必须使用列出消息编号的LIST命令。然后发出一个或多个RETR命令,其中包含上一列表中的单个消息编号。消息编号不一定从1开始!另请参阅我对有关调试此问题的问题的评论

例如:

LIST
+OK 2 messages (4095)
1 710
2 3385
.
RETR 1
+OK 710 octets
Return-Path: <john@example.com>
...
列表
+OK 2消息(4095)
1 710
2 3385
.
RETR 1
+OK 710八位字节
返回路径:
...

iv尝试了许多类似于“RETR 1”“RETR 1”“RETR”+1 ect的功能,但仍然无效您在阅读完结果后是否尝试过将
退出
?似乎它可能决定不发送结果,因为您已经说过“我完成了,再见”。您可以帮自己和我们一个忙,并列出服务器的响应行。如果在日志中混合输出和输入,效果会更好。首先,它更适合于调试,其次,只有在所有命令发送后才读取所有内容是不必要的,有些服务器不支持流水线。