ItGo.me Focus on IT Recommend

Home > pop3 - Reading mails from gmail account in asp.net

pop3 - Reading mails from gmail account in asp.net

2020阿里云最低价产品入口,含代金券(新老用户有优惠),
入口地址https://www.aliyun.com/minisite/goods

up vote 1 down vote favorite i want to read the mails from gmail account.. i tried to login.. and was successfull.. but unable to get the mails from the inbox.. below is the code i used for logging in... try

{

TcpClient tcpclient = new TcpClient(); // create an instance of TcpClient

tcpclient.Connect("pop.gmail.com", 995); // HOST NAME POP SERVER and gmail uses port number 995 for POP

System.Net.Security.SslStream sslstream = new SslStream(tcpclient.GetStream()); // This is Secure Stream // opened the connection between client and POP Server

sslstream.AuthenticateAsClient("pop.gmail.com"); // authenticate as client

//bool flag = sslstream.IsAuthenticated; // check flag

System.IO.StreamWriter sw = new StreamWriter(sslstream); // Asssigned the writer to stream

System.IO.StreamReader reader = new StreamReader(sslstream); // Assigned reader to stream

sw.WriteLine("username@gmail.com"); // refer POP rfc command, there very few around 6-9 command

sw.Flush(); // sent to server

sw.WriteLine("password");

sw.Flush();

sw.WriteLine("RETR 1"); // this will retrive your first email

sw.Flush();

sw.WriteLine("Quit "); // close the connection

sw.Flush();

string str = string.Empty;

string strTemp = string.Empty;

while ((strTemp = reader.ReadLine()) != null)

{

if (strTemp == ".") // find the . character in line

{

break;

}

if (strTemp.IndexOf("-ERR") != -1)

Recommend:c++ - Reading emails from gmail POP3 account using libCurl

ead emails from an gmail POP3 account just like the title says. Also is important to say that i need to download the attachments (is encode base64) of the mail and its body. The fact is that everyone recommend to use libCurl for this task,

{

break;

}

str += strTemp;

}

Response.Write(str);

Response.Write("" + "Congratulation.. ....!!! You read your first gmail email ");

}

catch (Exception ex)

{

Response.Write(ex.Message);

}

can anyone please tell me how can i get the actual mails from the inbox. asp.net pop3 gmail-pop incoming-mail
  |
  this question asked Sep 8 '11 at 22:20 Abbas 1,706 20 69 132



 |  2 Answers

up vote 0 down vote ---Accepted---Accepted---Accepted---

You should read server responses as soon as you issue a command. You have not logged in to Gmail successfully - you should use POP3 commands like USER, PASS Your code fails if email contains "-ERR" text str += strTemp; is going to kill your app when you revive email with a large attachment I'd recommend not reinventing the wheel - there are libraries for POP3 access.
  |
  this answer answered Sep 12 '11 at 10:02 Pawel Lesnikowski 4,950 3 28 36



 |  up vote 1 down vote Have you had a look at Mail.net, I have not had need to use it myself but I here good things about it. Cheers
  |
  this answer answered Sep 8 '11 at 22:29 Iain 4,032 2 19 39

 | 

Recommend:asp.net - How to fetch new mail from Gmail Inbox using POP3 Command

my account. But i can fetch only 255 oldest mail. Help me to fetch new mail from my inbox. public double GetEmailCount() { double count = 0; string response = SendCommand("STAT"); if (IsResponseOk(response))

up vote 1 down vote favorite i want to read the mails from gmail account.. i tried to login.. and was successfull.. but unable to get the mails from the inbox.. below is the code i

oriUlr:http://stackoverflow.com/questions/7355208/reading-mails-from-gmail-account-in-asp-net

------splitte line----------------------------