I'm using Exchange Web Services to connect to a mailbox and look for messages matching certain criteria, using FindItems with a SearchFilter.
I can get emails in a mailbox filtering on 'from' email address like this:
var service = new ExchangeService(ExchangeVersion.Exchange2010_SP1)
{
TraceEnabled = true,
Credentials = new WebCredentials(username, password)
};
var filter = new SearchFilter.ContainsSubstring(EmailMessageSchema.From, "some@email.com");
service.FindItems(WellKnownFolderName.Inbox, filter, new ItemView(50))
And I can filter on the DisplayTo
property like this:
var filter = new SearchFilter.ContainsSubstring(EmailMessageSchema.DisplayTo, "display name");
But as far as I can tell that only searches the recipient's display name. I want to search on an email address or domain name.
This doesn't return results when I would expect it to:
var filter = new SearchFilter.ContainsSubstring(EmailMessageSchema.ToRecipients, "some@email.com");
Is it possible to find all emails where the recipients list contains a specified email address?