Discuss this help topic in SecureBlackbox Forum

POP3: Receive only new messages arrived after the last session

To have this task done, the following steps should be performed:

  1. After logging in to a server, call GetMessageIDList() method to get the list of currently available messages.
  2. Compare the returned IDs with the ID list stored in the previous session (if any), and remove all the IDs, common for both lists.
  3. For each ID left in the "new IDs" list, call ReceiveMessage() and pass the corresponding message index to it. After the message has been received successfully, put its ID to the list of known messages to skip the message next time.
  4. If you delete a message, you may remove its ID from the list of known messages ONLY after graceful disconnection. If the session is broken for whatever reason or is not closed properly (with a QUIT command being sent), all the messages deleted during this session remain in the mailbox.



SBStringList.TElStringList knownIDs = new SBStringList.TElStringList();
// load known IDs
// sort the list to speed up searching
knownIDs.Sorted = true;

TSBPOP3MessageID[] ids = pop3.GetMessageIDList();

foreach (TSBPOP3MessageID id in ids)
    // check if the id is not known
    if (knownIDs.IndexOf(id.ID) < 0)
        // receive this new message

        // remember its ID to not download the message again

// save the list of known messages

Also, it is possible to call ReceiveMessageIDList() on the first step and to check message IDs in OnMessageID event handler one-by-one.

How To articles about POP3 client

Discuss this help topic in SecureBlackbox Forum