Aşağıdaki örnekte gmailden okuma yapılmıştır. Bu işlemi yapmadan önce gmail.com dan settings => pop => check to access email outside gmail web client seçeneğini seçtiğinizden emin olun.
POP rfc referansları için:http://www.faqs.org/rfcs/rfc1939
try
{
System.Net.Sockets.TcpClient tcpclient = new System.Net.Sockets.TcpClient(); // create an instance of TcpClient
tcpclient.Connect("pop.gmail.com", 995); //POP3 SERVER ADRESİ VE PORT NUMARASI
System.Net.Security.SslStream sslstream = new System.Net.Security.SslStream(tcpclient.GetStream()); // client ve pop server arasında bağlantı kurulur
sslstream.AuthenticateAsClient("pop.gmail.com"); // giriş yetkisi doğrulanır
//bool flag = sslstream.IsAuthenticated;
System.IO.StreamWriter sw = new System.IO.StreamWriter(sslstream); System.IO.StreamReader reader = new System.IO.StreamReader(sslstream);
sw.WriteLine("USER gmail_kullanici_adiniz@gmail.com"); // POP commandları gönderilir
sw.Flush(); // servera gönder
sw.WriteLine("PASS gmail_sifreniz");
sw.Flush();
sw.WriteLine("RETR 1"); // ilk email okunacak
sw.Flush();
sw.WriteLine("Quit "); // bağlantıyı kapat
sw.Flush();
string str = string.Empty;
string strTemp = string.Empty;
while ((strTemp = reader.ReadLine()) != null)
{
if (strTemp == ".") // . karakteri aranıyor
{
break;
}
if (strTemp.IndexOf("-ERR") != -1)
{
break;
}
str += strTemp;
}
Response.Write(str);
Response.Write("<BR>" + "Tebrikler.. ....!!! İlk mailinizi okudunuz ");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
5 kişi tarafından 4.2 olarak değerlendirildi
- Currently 4,2/5 Stars.
- 1
- 2
- 3
- 4
- 5