EWS SearchFilter.ContainsSubstring to filter on Sender Email Address

不想你离开。 提交于 2019-12-05 21:18:08

I worked out that the IsEqualTo filter works with From/Sender, and it doesn't care about case-sensitivity issues, so it's probably what I should have tried to begin with.

The code to match an email address is:

sfilter = New SearchFilter.IsEqualTo(EmailMessageSchema.From, New EmailAddress(Message.FromAddress))
MailItems = service.FindItems(FailureFolder.Id, sfilter, iv)

I still don't know how to find all emails from users at the same domain though.

More Info:

I really needed to filter by Sender Domain and did that by pulling the entire folder contents down and filtering in .Net code. Even that causes problems.

Basically to keep things quick and tight, I tried to pull all the data with a PropertySet:

New PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.Sender)

Filtering still didn't work, yet email addresses still showed in my list of items view. Well it turns out that the value of Message.Sender contains some kind of ActiveDirecty path in it until you call LoadPropertiesForItems. After LoadPropertiesForItems, it's an email address.

Note that my earlier attempt to filter at the server was scuppered because filtering would have to occur against the ActiveDirectory path style of string.

This is all highly confusing, and not at all user friendly.

If anybody has any idea on how to filter by email domain at the server, let me know!

Mark

What is your goal? Sender isn't a string property, so I'm not surprised that the results are odd with ContainsSubstring. I tried it against Office 365 and it worked, but older versions of Exchange may not be as "smart" about handling this kind of query. Depending on what you're trying to achieve, there may be a better filter.

if(emailSenderList.size() == 1) { return new SearchFilter.IsEqualTo(EmailMessageSchema.From, emailSenderList.get(0)); }

return new SearchFilter.SearchFilterCollection(LogicalOperator.Or, emailSenderList.stream().map(em -> new SearchFilter.IsEqualTo(EmailMessageSchema.From, em)).toArray(SearchFilter.IsEqualTo[] :: new));

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!