Solved

POP3, C# and Response from Command?

Posted on 2014-10-03
6
215 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 34

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
Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

 
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 34

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

630 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