7
votes

I have used an open source code from CodeProject to read email from incoming mail server(POP Server). The code can be found at following location: http://www.codeproject.com/KB/IP/Pop3MimeClient.aspx

So far it works fine; I can read emails.

My objective of using this code was to retrieve emails from a POP server and process them.

My problem is: If I use Gmail's pop server "pop.gmail.com" and run the appplication, I get only those emails that I have not retrieved since the last time I ran the application. But if I use my client's POP server every time I run the application I get all the emails in the pop server.

For example:
If I use Gmail POP server: pop.gmail.com
I have three emails in the pop server. I haven't run the application. I am running the application for the first time. Application reads the email; this time I will get all three emails. I run the application second time; my application will not read any emails this time because I have already read the 3 existing ones. This is fine; this is what I want.

Now I send an email to pop.gmail.com. I run the application again for the third time; this time I will only get the email that has just arrived, that is the fourth one. This is good behaviour; this is what I want.

But if I use my client's POP server:
No matter how many times I run the application, it reads all the emails in the mail box.

This will create a problem for me, because I am thinking of building a window service that will read emails from pop server and process them. This service will run continuously. I will process emails in the POP server then sleep for let's say 1 minute and the process the emails again. If the application downloaded from CodeProject reads all the emails all the time, my clients mailbox can have like thousands for email in this mail box, so this would not be feasible for me.

Are there some settings that are to be made at my client's POP server that will allow my application to retrieve only those emails that I have not read since last time I ran the service?

1

1 Answers

4
votes

Do not use Gmail's implementation of POP or IMAP as canonical; both of these protocols behave differently with Gmail accounts than with virtually any other server.

To answer your question, you have two approaches that you can take:

  1. Keep track of the message ID's of the messages that you've seen and ignore them on subsequent connections (this will leave the messages on the server for another client to download).
  2. Issue the DELE command after downloading a message, which will remove it from the server.