Question

The scenario is a Windows Service connects to an outlook.com or a gmail.com POP3 account using OpenPOP. It finds existing emails if there are any (i.e. client.getMessageCount() returns a value larger than zero).

The service keeps the connection open and rechecks for new messages.

The problem is that if i send email to that account after the service has connected then the getMessageCount() always returns zero until the service automatically re-cycles the pop connection.

I'm hoping someone has had the same issue.

I cannot resolve the issue by more frequent pop diconnect/reconnects as some providers (like outlook.com) have limits to time between connects.

Was it helpful?

Solution

The POP3 specification mentions that a mailbox is locked while a client has it open. Therefore no messages can appear.

Think of this scenario: Most servers assigns new messages a low message number. You have just fetched all the message numbers:

1 - Foo message
2 - Bar message

You now want to delete the Foo message, but the server updates the maildrop to look like:

1 - Baz message
2 - Foo message
3 - Bar message

You send the command DELE 1, and have now marked the Baz and not the Foo message to be deleted. The POP3 protocol was developed when internet was a sparse resource and you were not always connected. If you want to have live updates to a maildrop, you should use the much newer IMAP protocol instead.

If you keep using POP3, you will have to disconnect and connect again to have updates. Notice that most servers does not allow clients to continue to connect/disconnect in a fast manner, they will simply reject your authentication if you are connecting too often.

Also notice that Gmail have a strange POP3 implementation. See What non-standard behaviour features does Gmail exhibit, when it is programmatically used as a POP3 server?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top