How can I fetch all emails from Exchange 2010 in the least amount of EWS calls?
Our mailbox has 50k+ emails with 2k~ folders. I've tried iterating through each folder but this takes hours to fetch all of my emails. My current approach is to fetch all folders from the mailbox then make a list of search filters essentially filtering all items that have a parent folder id of n.
Here is what I have so far.
var allFolders = exchangeService.FindFolders(folderId,
new FolderView(int.MaxValue) {Traversal = FolderTraversal.Deep});
var searchFilterCollection = new List<SearchFilter>();
foreach(var folder in allFolders)
searchFilterCollection.Add(new SearchFilter.SearchFilterCollection(LogicalOperator.Or,
new SearchFilter.IsEqualTo(ItemSchema.ParentFolderId, folder.Id.ToString())));
var itemView = new ItemView(int.MaxValue)
{
PropertySet = PropertySet.FirstClassProperties
};
var findItems = exchangeService.FindItems(folderId,
new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection), itemView);
The error I receive it The property can not be used with this type of restriction.
.