read gmail


You can also try simple hotmail email reading code published here

http://www.revenmerchantservices.com/post/2009/09/29/ASPnet-read-email-hotmail.aspx


I have planeed to extend post here with pop3 SMTP and IMAP protocol usages.

The complete opensource project is available for download and use is at here
http://sourceforge.net/projects/hpop/

The code below is just for explanation about how it works with the help of ver very simple calls
using System;
using
System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.IO;
using
System.Net.NetworkInformation;
using
System.Net.Security;
using
System.Net.Sockets;

protected void Button9_Click(object sender, EventArgs e)

{
  
try
  

    
// create an instance of TcpClient

        TcpClient tcpclient = new TcpClient();    

     // HOST NAME POP SERVER and gmail uses port number 995 for POP

         tcpclient.Connect("pop.gmail.com", 995);

     // This is Secure Stream // opened the connection between client and POP Server

        System.Net.Security.SslStream sslstream = new SslStream(tcpclient.GetStream());

     // authenticate as client  

           sslstream.AuthenticateAsClient("pop.gmail.com");

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

    // Asssigned the writer to stream 

       System.IO.StreamWriter sw = new StreamWriter(sslstream);

     // Assigned reader to stream

       System.IO.StreamReader reader = new StreamReader(sslstream);

    // refer POP rfc command, there very few around 6-9 command

      sw.WriteLine("USER your_gmail_user_name@gmail.com");

    // sent to server

      sw.Flush();       sw.WriteLine("PASS your_gmail_password");

      sw.Flush();

      // RETR 1 will retrive your first email. it will read content of your first email

       sw.WriteLine("RETR 1");

       sw.Flush();
     // close the connection

       sw.WriteLine("Quit ");
       sw.Flush();        string str = string.Empty;
       string strTemp = string.Empty;
       while ((strTemp = reader.ReadLine()) != null)
      {
         
// find the . character in line
       
if (strTemp == ".")
        {
           break;
         }
        if (strTemp.IndexOf("-ERR") != -1)
        {
           break;
         }
        str += strTemp;
      }
    
     Response.Write(str);
     Response.Write("<BR>" + "Congratulation.. ....!!! You read your first gmail email ");
    }

     catch (Exception ex) 
    {
        Response.Write(ex.Message);
    }
}
 


Now here I have explained how to read email attachments using your POP3. you can use your company POP3 email account.
Follow this link:
http://revenmerchantservices.com/page/Read-pop3-email-attachments-component.aspx

Satalaj  .