Hy,
I have an application that sends mails with Gmail SMTP server (smtp.gmail.com) using SSL.
Now I want to read the emails from that account, does anyone have any idea how can I make this programatically in C# and ASP.NET?
At this point I'm using this code:
TcpClient tcpClient = new TcpClient();
tcpClient.Connect("pop.gmail.com", 587);
NetworkStream netStream = tcpClient.GetStream();
System.IO.StreamReader strReader = new System.IO.StreamReader(netStream);
Label7.Text = strReader.ReadLine() + "<br />";
//Label7.Text = "Server connected!";
byte[] WriteBuffer = new byte[1024];
ASCIIEncoding enc = new System.Text.ASCIIEncoding();
WriteBuffer = enc.GetBytes("USER " + TextBox4.Text + "\r\n");
netStream.Write(WriteBuffer, 0, WriteBuffer.Length);
Label7.Text += strReader.ReadLine() + "<br />";
WriteBuffer = enc.GetBytes("PASS " + TextBox5.Text + "\r\n");
netStream.Write(WriteBuffer, 0, WriteBuffer.Length);
Label7.Text += strReader.ReadLine() + "<br />";
WriteBuffer = enc.GetBytes("LIST\r\n");
netStream.Write(WriteBuffer, 0, WriteBuffer.Length);
String ListMessage;
while (true)
{
ListMessage = strReader.ReadLine();
if (ListMessage == ".")
{
break;
}
else
{
Label7.Text += ListMessage + "<br />";
continue;
}
}
WriteBuffer = enc.GetBytes("QUIT\r\n");
netStream.Write(WriteBuffer, 0, WriteBuffer.Length);
Label7.Text += strReader.ReadLine() + "<br />";
And when I debug it it's shows that it's connected but no response in retrieving emails.