Search code examples
asp.net.netopenpop

OpenPop.Net Exception


I am using OpenPop.net in my application. What this application does is that it downloads mails from a pop3 account saves all the attachments (CSV files) and processes them. This processing takes a lot of time. I am getting this exception which I am not able to figure out:

Exception message: OpenPop.Pop3.Exceptions.PopServerException: The stream used to retrieve responses from was closed
   at OpenPop.Pop3.Pop3Client.IsOkResponse(String response)
   at OpenPop.Pop3.Pop3Client.SendCommand(String command)
   at OpenPop.Pop3.Pop3Client.DeleteMessage(Int32 messageNumber)

At the end of processing the CSV, the mails are deleted from the pop3 account. I believe this is where this exception is happening.


Solution

  • You are really having two issues here. One is that you are doing a lot of processing while being connected to the POP3 server. When you are idle too long, the server will simply disconnect you to save resources. What you should do, is fetch one email, process the attachments and then reconnect to fetch the next. You could also fetch all the attachments and then process them offline.

    Second, I guess you are connecting to a gmail account. Gmail has some weird characteristics. A thread tries to find these characteristics. One of them is that, when you have fetched an email, it will not be available in the next POP3 session with the server. You can connect using a special username, where you append recent: in front of your normal username. This will show you the emails received in the last 30 days, despite of having been showed to an earlier POP3 session.

    Hope it helps.