Solved

POP3, C# and Response from Command?

Posted on 2014-10-03
6
206 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
  • 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 33

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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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 33

Accepted Solution

by:
ste5an earned 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

813 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now