In a previous project where I used EWS, my search criteria was much simpler: find emails with "xxx" in the Subject.
I'm now building this code into a more multi-purpose application; I will be monitoring various mailboxes for various criteria, for example:
Find all mail items where the recipient is "[email protected]", AND subject contains "xxx" AND (body contains "yyy" OR body contains "zzz")
However, using a SearchFilterCollection, although I can add multiple SearchFilters, I don't see how to apply different logical operators... there seems to be one logical operator per SearchFilterCollection:
SearchFilterCollection sfc = new SearchFilterCollection(LogicalOperator.Or, new SearchFilter.ContainsSubstring(ItemSchema.Subject, "Test"));
I suppose one solution would be to find a superset of the desired mail items, and then filter them more accurately later, when they are being processed. But I was wondering if there is a better way of filtering at the start, using SearchFilters or any other means?
You could build-up your complex Searchfilter using SearchFilter.SearchFilterCollection (LogicalOperator, SearchFilter[])
Check: HOW TO: Build a complex search using SearchFilter and SearchFilterCollection in EWS Managed API 1.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With