阅读只有TcpClient的POP3服务器和StreamWriter / StreamReader的 [英] Reading a POP3 server with only TcpClient and StreamWriter/StreamReader

查看:174
本文介绍了阅读只有TcpClient的POP3服务器和StreamWriter / StreamReader的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to read mails from my live.com account, via the POP3 protocol.

我发现服务器是pop3.live.com和端口(如果是995)。

I've found the the server is pop3.live.com and the port if 995.

我不打算使用预制库,我使用NetworkStream和StreamReader / StreamWriter作业。我需要弄清楚这一点。因此,此处提供的任何答案: http://stackoverflow.com/questions/44383 / reading-email-using-pop3-in-c 不是有用的。

I'm not planning on using a pre-made library, I'm using NetworkStream and StreamReader/StreamWriter for the job. I need to figure this out. So, any of the answers given here: http://stackoverflow.com/questions/44383/reading-email-using-pop3-in-c are not usefull.

它是一个更大的程序的一部分,但我做了一个小测试如果它工作。无论如何,我没有得到任何东西。这是我使用的代码,我认为应该是正确的。

It's part of a larger program, but I made a small test to see if it works. Eitherway, i'm not getting anything. Here's the code I'm using, which I think should be correct.

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

this code is old, please refer to the second block problem solved.

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错误。

Visual Studio debugger constantly falls over tc.Connect("pop3.live.com",995); Which throws an "A socket operation was attempted to an unreachable network 65.55.172.253:995" error.

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

So, I'm sending from port 8000 on my machine to port 995, the hotmail pop3 port. And I'm getting nothing, and I'm out of ideas.

第二块:显然我没有写退出命令。

Second block: Problem was apparently that I didn't write the quit command.

代码:

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);
}


推荐答案

网络流量使用Wireshark?是否正在发送任何邮件?

What happens if you view the Network Traffic using Wireshark? Is it sending anything at all?

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

I can't connect via telnet to pop3.live.com at that port either. Have you managed to successfully connect via a pop3 email client ever?

这篇关于阅读只有TcpClient的POP3服务器和StreamWriter / StreamReader的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆