When I connect to pop3.live.com the connection is fine and it also shows me the amount of messages I have and the size of the file but when I try and use “RETR” to get the messages and show them on a console application nothing is presented.
Here is what I have so far
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();
First you have to use the LIST command, which lists the message numbers. Then issue one or more RETR commands with a single message number from the previous list. Message numbers does not necessarily start from 1! See also my comment on your question about debugging this issue.
For example: