0 votes
by (740 points)

Hi, I'm using the code below to retrieve a list of items from an EWS hosted mailbox that contains 5000+ items.
It does this once a minute on a polled cycle.
On 2 occasions in the last month, it has failed to read all of the items, once stopping after a single page of 1000 items and the second time after 5 pages of 1000 items, both times giving no error at all, just an abbreviated list with an incorrect count, which has caused havoc for our synchronization logic, as the next time we look, the mails are back in the list.

It would appear to me that the PageResult.IsLastPage is reporting that it is the last page when there are more pages left, I can't see any other way out of the loop.

Rebex.Ews.dll is version 1.0.5759.2

Code below;

                // We must do this in pages so that we don't hit any server throttling limits on EWS
                EwsMessageCollection ewsMessageCollection=new EwsMessageCollection();
                int offset = 0;
                int pageSize = 1000;
                //EwsMessageCollection ewsMessageCollection2 = mailBoxMonitor.ExchangeWS.GetMessageList(new EwsFolderId(mailBoxMonitor.MailBoxSettings.Folder), EwsItemFields.Fast);
                while (true)
                    // get items of next page
                    EwsMessageCollection thisPageOfMessages =
                            new EwsFolderId(mailBoxMonitor.MailBoxSettings.Folder),
                            EwsPageView.CreateIndexed(offset, pageSize));

                    // add this page of items to our master list, bu tonly the items that are actually messages
                    // we could see calendar invites and the like
                    foreach (EwsMessageInfo thisItem in thisPageOfMessages)
                        if (thisItem.MessageType == EwsMessageType.Message)

                    // break if this is the last page
                    if (thisPageOfMessages.PageResult.IsLastPage)

                    // set next offset
                    if (thisPageOfMessages.PageResult.NextOffset.HasValue)
                        offset = thisPageOfMessages.PageResult.NextOffset.Value;
                        offset += pageSize;
                //EwsMessageCollection ewsMessageCollection = mailBoxMonitor.ExchangeWS.GetMessageList(new EwsFolderId(mailBoxMonitor.MailBoxSettings.Folder), EwsItemFields.Fast);
                DateTime retrieveEnd = DateTime.UtcNow;
                TimeSpan retrievalTime = retrieveEnd - retrieveStart;
                infoLogMessage += "Retrieved " + ewsMessageCollection.Count.ToString() + " Unique Ids from EWS provider, total retrieval call time = " + retrievalTime.ToString() + Environment.NewLine;
Applies to: Rebex Secure Mail

1 Answer

+1 vote
by (15.2k points)


your Rebex EWS assembly version indicates that you are using one of the beta build prior to first release. Please try to update to most recent released build to see if the issue is still present. When confirming if the issue is still present, please create a DEBUG log following this KB article. It should contain values retrieved from the server, which we simply propagate to our API. That log should reveal if the paging works properly.

Your code seems correct to me, so I wonder what the log will contain.

by (740 points)
I set up a test on an Office365 account to see if I could replicate the behaviour.
6,000 plus emails were sent to the test mailbox.
Using the 1.0.6068.1 build of Rebex.Ews.dll (which I know isn't the latest version, but is the latest version we have used in a product release), it works perfectly.
Thanks for taking the time to look at my issue.