I found example of receiving messages from mail box:
// create an instance of TcpClient
TcpClient tcpclient = new TcpClient();
// HOST NAME POP SERVER and gmail uses port number 995 for POP
tcpclient.Connect("pop.gmail.com", 995);
// This is Secure Stream // opened the connection between client and POP Server
System.Net.Security.SslStream sslstream = new SslStream(tcpclient.GetStream());
// authenticate as client
sslstream.AuthenticateAsClient("pop.gmail.com");
//bool flag = sslstream.IsAuthenticated; // check flag
// Asssigned the writer to stream
System.IO.StreamWriter sw = new StreamWriter(sslstream);
// Assigned reader to stream
System.IO.StreamReader reader = new StreamReader(sslstream);
// refer POP rfc command, there very few around 6-9 command
sw.WriteLine("USER [email protected]");
// sent to server
sw.Flush();
sw.WriteLine("PASS your_gmail_password");
sw.Flush();
// this will retrive your first email
sw.WriteLine("RETR 1");
sw.Flush();
// close the connection
sw.WriteLine("Quit ");
sw.Flush();
string str = string.Empty;
string strTemp = string.Empty;
while ((strTemp = reader.ReadLine()) != null)
{
// find the . character in line
if (strTemp == ".")
{
break;
}
if (strTemp.IndexOf("-ERR") != -1)
{
break;
}
str += strTemp;
}
But I don't understand how to print message body in rich text box for example. Which string contains response? Can anyone help me?
Thank you very much!
As I wrote in reply to your other, nearly identical, question: you really need to read the MIME specifications and the POP3 specification if you ever hope to write a mail client.
Or you could use a library which has done most of the hard work for you, such as MimeKit and MailKit.
You'll still really need to have at least a basic understanding of MIME, but at least you won't have to write a parser for it (which is non-trivial seeing as how many messages in the real world do not follow the specifications - often having been written by folks who never bothered to actually read the specifications).