I have a program that once every few hours synchronizes an Office 365 Online mailbox to a database collection. In order to pull down the latest messages, I'm using ExchangeService C# API
However, every once in a while, newest messages for certain contacts will not come thru. When I search for the messages via Outlook, it shows them no problem. But, the C# code that searches for messages by email ID does not find them.
Am I missing a criteria in my search strings? Or perhaps there is some caching going on - how do I disable it?
I usually have 10-20 messages per search result (this is not thousands)
Here's the relevant code:
foreach (var item in customer.Contacts)
{
search.Add(new SearchFilter.ContainsSubstring(EmailMessageSchema.ToRecipients, item.Email));
search.Add(new SearchFilter.ContainsSubstring(EmailMessageSchema.CcRecipients, item.Email));
search.Add(new SearchFilter.ContainsSubstring(EmailMessageSchema.From, item.Email));
search.Add(new SearchFilter.ContainsSubstring(EmailMessageSchema.Sender, item.Email));
search.Add(new SearchFilter.ContainsSubstring(ItemSchema.DisplayTo, item.Email));
search.Add(new SearchFilter.ContainsSubstring(ItemSchema.Body, item.Email));
}
var filter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, search.ToArray());
var inboxCollection = _exchangeClient.FindItems(WellKnownFolderName.Inbox, filter,
new ItemView(1000) {PropertySet = PropertySet.FirstClassProperties});