POP3.NET

Recently I needed to retrieve messages from POP3 server but I could not find any .NET Open Source library for this task. For this reason I developed my own library (based in the POP3 code used in WCF Mail Transport) and now I share it with the community.

Download the code and a sample of use from here.

[UPDATE: New version here]

About Rodolfo Finochietti

Uma's father, and a programmer ;)

Posted on 07/07/2008, in .NET, Tools and tagged . Bookmark the permalink. 19 Comments.

  1. Uzair Lakhani

    Dear Sir,

    Can your POP3 client be used for gmail or not? The port is hard-coded to 110 while for gmail 995 is used.

    Thanks,
    Uzair Lakhani,
    Software Developer,
    DTS Inc Pakistan,
    Karachi, Pakistan

  2. Uzair Lakhani

    Dear Sir,

    I changed the server to “pop.gmail.com” and port to 995 but getting following exception

    System.ArgumentOutOfRangeException was unhandled
    Message=”Index and length must refer to a location within the string.\r\nParameter name: length”
    Source=”mscorlib”
    ParamName=”length”
    StackTrace:
    at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
    at System.String.Substring(Int32 startIndex, Int32 length)
    at Pop3.Pop3Client.Connect(String server, String username, String password) in D:\Pop3\Pop3\Library\Pop3Client.cs:line 50
    at TestClient.Program.Main(String[] args) in D:\Pop3\Pop3\TestClient\Program.cs:line 31
    at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ThreadHelper.ThreadStart()
    InnerException:

    Basically I think the response function after the TCPClient connect function is returning NULL string. OK is not returned. May be due to the fact that gmail is not following TCP but UDP protocol.

    Thanks,
    Uzair Lakhani

  3. Dear Sir,

    Thanks for posting the updated libraray. The new one works fine with gmail, hotmail.

    Thanks,
    Uzair Lakhani

  4. Julio C. Hernández D.

    Rodolfo, esta librería me parece excelente. Te felicito.
    Tengo una duda: como puedo acceder a los archivos adjuntos de los mensajes?

    Saludos
    Julio C. Hernández D.
    Programador
    VSM
    Tams, Mex

    • Hola Julio,

      Gracias por tu comentario!

      Con esta versión tienes que acceder pasear el mensaje MINE a mano. Estoy trabajando en la próxima versión que ya tendrá el parser incorporado, y se podrá acceder a los archivos directamente.

      • Julio C. Hernández D.

        Muchas gracias Rodolfo, estaré atento a la próxima versión. Saludos.

  5. please tell me how to download /upload .pdf files using asp.net

  6. Hi sir,

    please can you say me how to use and call these pop3 code in aspx pages

    • Hi Ramesh,

      This is the code that you need to put inside of an event in a ASPX pages:

      Pop3Client pop3Client = new Pop3Client( );
      pop3Client.Connect( “SERVER”, “USERNAME”, “PASSWORD”, true );

      //Retrieve message list
      var messages = pop3Client.List( );

      //Retrieve messages
      foreach ( Pop3Message message in messages )
      {
      pop3Client.Retrieve( message );

      Console.WriteLine( “MessageId: {0}”, message.MessageId );
      Console.WriteLine( “Date: {0}”, message.Date );
      Console.WriteLine( “From: {0}”, message.From );
      Console.WriteLine( “To: {0}”, message.To );
      Console.WriteLine( “Subject: {0}”, message.Subject );
      }

      //Disconnect from the server
      pop3Client.Disconnect( );

  7. Can you pull the attachments from the emails with your code? If so, how do you do that in asp .net?

  8. hi Rodolfo,

    i just implement your code in asp.net 3.5.its very nice article.but i got an error
    “System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.” can you help me fix this.

    • Hi,

      The problem is that you haven’t configured a valid SSL certificate.

      You could ignore those error by settings the ServerCertificateValidationCallback static property in your Application_Start:

      System.Net.ServicePointManager.ServerCertificateValidationCallback += (s, cert, chain, sslPolicyErrors) => true;

      Regards!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 704 other followers

%d bloggers like this: