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]

19 thoughts on “POP3.NET”

  1. 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. 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. 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

    1. 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.

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

  5. Hi sir,

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

    1. 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( );

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

    1. Hi Betty,

      My library doesn’t support attachments out of the box. The only way to download the attachments is parse the raw MINE content in the body.

  7. 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.

    1. 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!

      1. hi,

        thanks for your reply, but am using web application which was not support this function call.

Leave a Reply to ShobanaCancel reply