I am searching an email inbox (on Exchange 2010) using Exchange Web Services.
In my SearchFilterCollection I would like to include the From.Address
property of the Email message, as I only want to retrieve emails that include a certain domain (such as @domain.co.uk)
here is my code:
SearchFilter.SearchFilterCollection searchFilterCollection = new SearchFilter.SearchFilterCollection(LogicalOperator.And);
searchFilterCollection.Add(new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
searchFilterCollection.Add(new SearchFilter.IsEqualTo(EmailMessageSchema.HasAttachments, true));
// **** PROBLEM HERE ON BELOW LINE****
searchFilterCollection.Add(new SearchFilter.ContainsSubstring(EmailMessageSchema.From, "@domain.co.uk")); //
// add the exceptions
for (int iEx = 0; iEx < e2c.emailExceptions.Count; iEx++)
{
searchFilterCollection.Add(new SearchFilter.Not(new SearchFilter.ContainsSubstring(EmailMessageSchema.Subject, e2c.emailExceptions[iEx])));
}
ItemView view = new ItemView(100);
view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
// Find the first email message in the Inbox that has attachments. This results in a FindItem operation call to EWS.
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Inbox, searchFilterCollection, view);
is there a good way to include the email address in the SearchFilter?