0

I was able to connect and retrieve email from my POP3 email server. But I am getting this error in a few seconds of reading the email if the retrieve task needs few more time.

Here is how I connected

` using (Pop3Client client = new Pop3Client())
{

                client.Connect(emailCaptureClient.MailServerUrl, emailCaptureClient.MailServerPort, true, receiveTimeout, sendTimeout, null);

                client.Authenticate(emailCaptureClient.MailServerUserName, emailCaptureClient.MailServerPassword);


                for (messageNumber = 1; messageNumber <= client.GetMessageCount(); messageNumber++)

                {

                    try
                    {
                        MessageHeader headers = client.GetMessageHeaders(messageNumber);

                        toAddress = headers.To;                                        

                        RetrieveEmail(client, emailCaptureClient, headers, toAddress, messageNumber, true);

                    }
                    catch (Exception e) 
                    {
                        //
                    }


                }
                client.Disconnect();                   
            }`             
  • Are you inside a corporate network that uses Outlook? Does the code work from home? – jdweng Jan 10 '20 at 17:08
  • No, I am not using Outlook. My project connects fine and retrieves successfully if it runs without delay. However, while debugging it gives me this error if I delay a moment in going through the code – Simon Mekit Jan 10 '20 at 17:24
  • You can only connect to the server once. You cannot have two connections with the same source IP destination IP, and Port number. So you cannot loop which is causing a second connection to be made which gives the error "Forcibly closed" when you make the 2nd connection. – jdweng Jan 10 '20 at 17:31
  • I have opened single connection in my visual studio project. Is it a timeout issue? – Simon Mekit Jan 10 '20 at 17:40
  • Is the failure occurring the 1st time you make a connection or after 1st connection. May be the first connection isn't closing before you make a 2nd connection. How long are you stopped during debug? – jdweng Jan 10 '20 at 17:51
  • if I connect and run it without break point in my code it retrieves all the emails in my emails server. However if I put a break point in my code and left it a moment time, the connection doesn't work showing the exception i mentioned. – Simon Mekit Jan 10 '20 at 18:09
  • I have updated with timeout value of 1000000 for both receive and sendTimeout. client.Connect(emailCaptureClient.MailServerUrl, emailCaptureClient.MailServerPort, true, receiveTimeout, sendTimeout, null); another exception raised: OpenPop.Pop3.Exceptions.PopServerException: 'The stream used to retrieve responses from was closed' – Simon Mekit Jan 10 '20 at 18:49

0 Answers0