Reading a POP3 server with only TcpClient and StreamWriter/StreamReader

Posted by WebDevHobo on Stack Overflow See other posts from Stack Overflow or by WebDevHobo
Published on 2010-03-13T21:43:55Z Indexed on 2010/03/13 21:55 UTC
Read the original article Hit count: 589

Filed under:
|

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

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

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.

public Program() {
    string temp = "";
    using(TcpClient tc = new TcpClient(new IPEndPoint(IPAddress.Parse("127.0.0.1"),8000))) {
        tc.Connect("pop3.live.com",587);
        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);
}

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

© Stack Overflow or respective owner

Related posts about c#

Related posts about pop3