Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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"); // refer POP rfc command, there very few around 6-9 command
        sw.Flush(); // sent to server
        sw.WriteLine("password");
        sw.Flush();
        sw.WriteLine("RETR 2"); // 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)
            {
                break;
            }
            str += strTemp;
        }
        Response.Write(str);
        Response.Write("<BR>" + "Congratulation.. ....!!! You read your first gmail email ");

I read a mail using above code but it comes only encrypted format.!

Help me in this
Thanks
Posted
Updated 23-Dec-10 18:14pm
v3
Comments
Toniyo Jackson 15-Dec-10 4:54am    
Always write your code inside code block.

What exactly does 'encrypted' mean? Please provide an example of your result.
 
Share this answer
 
Mails have a special format which is defined by RFC 5322[^] and some MIME[^] types for different kinds of mails. It will generally contain Message Header and body. You need to parse the mail to get all the information and the actual mail.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900