2

我正在尝试通过 POP3 协议从我的 live.com 帐户中读取邮件。

我发现服务器是 pop3.live.com,端口是 995。

我不打算使用预制库,我正在使用 NetworkStream 和 StreamReader/StreamWriter 来完成这项工作。我需要弄清楚这一点。所以,这里给出的任何答案:Reading Email using Pop3 in C# are not有用。

它是一个更大程序的一部分,但我做了一个小测试,看看它是否有效。不管怎样,我什么都得不到。这是我正在使用的代码,我认为应该是正确的。

编辑:这段代码很旧,请参考解决的第二个块问题。

public Program() {
    string temp = "";
    using(TcpClient tc = new TcpClient(new IPEndPoint(IPAddress.Parse("127.0.0.1"),8000))) {
        tc.Connect("pop3.live.com",995);
        using(NetworkStream nws = tc.GetStream()) {
            using(StreamReader sr = new StreamReader(nws)) {
                using(StreamWriter sw = new StreamWriter(nws)) {
                    sw.WriteLine("USER " + user);
                    sw.Flush();
                    sw.WriteLine("PASS " + pass);
                    sw.Flush();
                    sw.WriteLine("LIST");
                    sw.Flush();
                    while(temp != ".") {
                        temp += sr.ReadLine();
                    }
                }
            }
        }
    }
    Console.WriteLine(temp);
}

Visual Studio 调试器不断tc.Connect("pop3.live.com",995);失败,引发“尝试对无法访问的网络 65.55.172.253:995 进行套接字操作”错误。

所以,我从我机器上的端口 8000 发送到端口 995,hotmail pop3 端口。而且我什么也没得到,而且我没有想法。


第二块:问题显然是我没有编写退出命令。

编码:

public Program() {
    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 " + user);
                    sw.Flush();
                    sw.WriteLine("PASS " + pass);
                    sw.Flush();
                    sw.WriteLine("LIST");
                    sw.Flush();
                    sw.WriteLine("QUIT ");
                    sw.Flush();

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

1 回答 1

0

如果您使用 Wireshark 查看网络流量会发生什么?它是否发送任何东西?

编辑:我也无法通过 telnet 连接到该端口的 pop3.live.com。您是否曾经通过 pop3 电子邮件客户端成功连接?

于 2010-03-13T21:47:59.027 回答