海蘭,C#,如何通過POP3
檢索來自Gmail服務器的郵件列表中我有一個使用SSL與Gmail SMTP服務器發送郵件(smtp.gmail.com)的應用程序。
現在我想閱讀該帳戶的電子郵件,有沒有人有任何想法如何在C#和ASP.NET編程方式?
在這一點上,我使用此代碼:
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 />";
當我調試它,它的顯示,它的連接,但在檢索電子郵件沒有反應。
在TcpClient.Connect地址中不應該是pop.gmail.com而不是smtp.gmail.com? – 2010-09-24 09:18:30
啊,是的,我的錯誤,我已編輯到pop.gmail.com,但我仍然有問題... – 2010-09-24 09:24:40