?
Solved

POP3, C# and Response from Command?

Posted on 2014-10-03
6
Medium Priority
?
217 Views
Last Modified: 2014-10-17
Hi,

I have an interesting dilemma that started a little while ago.

I have an exchange mailbox that I will access with OWA from a browser.

However, I have an application that will access the mailbox as well and perform most of the activity. That is where the strangeness is happening. Generally, there will be like 600 emails a day that will go into the Inbox and the application will process. As part of the process it will retrieve the necessary message and process it then issue the command to delete the message (DELE {Whatever the number of the message}). Again, for the large majority of the time it processes just fine. Yet, I will randomly get a message in it that just causes havoc. When that message in as in the Inbox more "normal" messages will come in BUT it will never delete those message. As a result, the inbox will build and build.

Here is a little snippet of the code:

try {
        pop3Stream.Write(commandBytes, 0, commandBytes.Length);
        if (isDebug) {
          isDebug=false;
          throw new IOException("Test", new SocketException(10053));
        }
      } catch (IOException ex) {
        //Unable to write data to the transport connection. Check if reconnection should be tried
        isSupressThrow = {execute reconnect};
        if (!isSupressThrow) {
          throw;
        }
      }
      pop3Stream.Flush();

      //read response from server
      response = null;
      try {
        response = pop3StreamReader.ReadLine();
      }catch (IOException ex) {
        //Unable to write data to the transport connection. Check if reconnection should be tried
        isSupressThrow = {execute reconnect}
        if (isSupressThrow) {
          //wait for response one more time
          response = pop3StreamReader.ReadLine();
        } else {
          throw;
        }
      }
      if (response==null) {
        throw new Pop3Exception("Server "+ popServer + " has not responded, timeout has occured.");
      }

Open in new window


Now, the problem is in that situation with the email that doesn't delete is that the
response

Open in new window

is "" there is would "normally" get like an "+OK".  All subsequent emails that hit this code get some other cryptic type message that doesn't look like a response from a command.

I need to take that one email that is causing everything out of the mailbox by moving it and only then will everything go back to processing normally.

Any ideas on this? Should I loop on the
response = pop3StreamReader.ReadLine();

Open in new window

line while the response is "" for a certain period of time?

Any thoughts or suggestions on this?

Any information would be greatly appreciated.
0
Comment
Question by:davism
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 40361217
not a POP expert, but there is also an Exchange WebServices API that works directly and well for me.
0
 
LVL 1

Author Comment

by:davism
ID: 40361222
I cannot change the code or anything nor does it make any since. Especially when this has been running fine for almost 2 years.

Any other thoughts or ideas related to this?
0
 
LVL 35

Expert Comment

by:ste5an
ID: 40361271
Just it was running for two years, doesn't mean that it was okay.

But I would assume that the problem may be your pop3Stream. How is it implemented?
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 1

Author Comment

by:davism
ID: 40361697
I will have to provide the info when I get connect to my work again. Once I do I will post the response to your question.

But help me understand, if it's been running fine and has processed over 100,000 emails with no problem but now all of a sudden starts (began on 9/11 actually) and is randomly  encountering an issue how would that constitute not being ok? The machine hasn't been patched so nothing has changed; it has been rebooted on normal quarterly schedules.

I know we have another test environment with a mailbox specific to test. It runs the same program just from a different machine accessing the same mailbox server. I have forwarded the culprit email to that test mailbox and the test server application (which is the same code) deleted it without a problem. But I would imagine the forwarding changed the header and all. How can I get that same email in a different mailbox? That way I could test more to try and isolate the problem with that email or emails like that.
0
 
LVL 35

Accepted Solution

by:
ste5an earned 1500 total points
ID: 40362084
The behaviour you've described sounds like the pop3stream is not capturing the Ok from the server. This can be a race condition. This maybe for example by a different bandwidth. My first approach would using a network sniffer to check whether the ok is sent and the timing looks like.
0
 
LVL 1

Author Closing Comment

by:davism
ID: 40387825
The result was that it had to be attempted again. The first read didn't capture the "+OK" the second attempt did.

Thanks for the info and responding. It's very much appreciated.
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question