I have created an application that will scan my entire mailbox, (Inbox, Sent Items, Deleted Items, Archive Inbox, Archive Deleted, and any sub-folders within those folders. I can read all my emails without any issues until I get to my Archive items. When inside the Archive items it is not able to scan one of my current emails. It can see that it is there however it will not retrieve retrieve the DateReceived, Policy Id, and Retention Date for that specific email. I can read all 143 documents in that folder and retrieve their values, except for that one specific email.
I am using the Microsoft.Exchange.WebServices to get access to my exchange mailbox. My SearchFilter is set to only find Items (EmailMessage) hat contain the DateReceived, Policy Id, and Retention Date. Based off this search filter I should only have emails that fit this criteria. However, I am unable to retrieve that one single email. The error message I get is as follows:
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ProcessWebException(WebException webException) at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request) at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request) at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.InternalExecute() at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute() at Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems[TItem](IEnumerable`1 parentFolderIds, SearchFilter searchFilter, String queryString, ViewBase view, Grouping groupBy, ServiceErrorHandling errorHandlingMode) at Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems(FolderId parentFolderId, SearchFilter searchFilter, ViewBase view) at BRM_App.csFolder.getItems(ItemTraversal itemTraversal, PropertyDefinitionBase[] propertyDefinitionBase, SearchFilter searchFilter) in :line 179
I have done extensive research and have found no possible solution for my issue. Any input is greatly appreciated. Here is the code where it crashes:
{
//Creates the List that will hold all the records
List<EmailMessage> emailItems = new List<EmailMessage>();
//Create a view with a page size of 1.
ItemView view = new ItemView(1, 0, OffsetBasePoint.Beginning);
view.Traversal = itemTraversal;
//Identify the DateTimeReceived properties to return
//Indicate that the base property will be the item identifier
view.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, propertyDefinitionBase);
//Used as a flag to verify if there are any more pages to view
bool flag = true;
while (flag == true)
{
FindItemsResults<Item> findResults = Service.FindItems(Id, searchFilter, view);
//Process each item
if (findResults.Items.Count > 0)
{
foreach (Item myItem in findResults.Items)
{
if (myItem is EmailMessage)
{
emailItems.Add((EmailMessage)myItem);
}
}
//If there are additional items in other views this
// will move to the next view for item retrieval
if (findResults.NextPageOffset.HasValue == true)
{
view.Offset = findResults.NextPageOffset.Value;
}
else
{
//Forces the loop to exit
flag = false;
}
}
else
{
//Forces the loop to exit
flag = false;
}
}
//Returns all the items
return emailItems;
}