I have created a windows test app in which i am connecting to my hotmail account and checking the unread mails there.Currently through my app ,i m getting the last mail from my hotmail account.
How can i get the latest mail and whether is it possible to get the subject and body of the latest mail using SSLStream object.
I am posting my code here.Please help me with this one.Any proper help will be appreciated.The place where it is written that "to get the first mail",i am only getting the total bytes of the first mail.Please help me to get the first email subject and body.
TcpClient mail = new TcpClient();
SslStream sslStream;
int bytes = -1;
mail.Connect("pop3.live.com", 995);
sslStream = new SslStream(mail.GetStream());
sslStream.AuthenticateAsClient("pop3.live.com");
byte[] buffer = new byte[2048];
// Read the stream to make sure we are connected
bytes = sslStream.Read(buffer, 0, buffer.Length);
string message = Encoding.ASCII.GetString(buffer, 0, bytes);
MessageBox.Show(message);
//Send the users login details
sslStream.Write(Encoding.ASCII.GetBytes("USER user_name\r\n"));
bytes = sslStream.Read(buffer, 0, buffer.Length);
string message1 = Encoding.ASCII.GetString(buffer, 0, bytes);
MessageBox.Show(message1);
//Send the password
sslStream.Write(Encoding.ASCII.GetBytes("PASS password\r\n"));
bytes = sslStream.Read(buffer, 0, buffer.Length);
string message2 = Encoding.ASCII.GetString(buffer, 0, bytes);
MessageBox.Show(message2);
// Get the first email
sslStream.Write(Encoding.ASCII.GetBytes("RETR 1\r\n"));
bytes = sslStream.Read(buffer, 0, buffer.Length);
string message4 = Encoding.ASCII.GetString(buffer, 0, bytes);
MessageBox.Show(message4);
string str = string.Empty;
string strTemp = string.Empty;
StreamReader reader = new StreamReader(sslStream);
while ((strTemp = reader.ReadLine()) != null)
{
// find the . character in line
if (strTemp == ".")
{
break;
}
if (strTemp.IndexOf("-ERR") != -1)
{
break;
}
str += strTemp;
}
MessageBox.Show(str);
}
With some modifications in the code i am able to access the hotmail account.But with the same code when i try to access the AOl account.I am getting IO exception.Can anyone help me to how to connect to AOL mail sysytem using this code.Thanks for any help.
I think you have to implement the pop protocol to get email for pop server; in your case hotmail. You will find good article about opening mails from pop3 servers like hotmail/gmail over here