EWS从电子邮件收件箱搜索中排除具有特定主题的电子邮件
本文关键字:电子邮件 排除 收件箱 搜索 EWS | 更新日期: 2023-09-27 17:49:41
我正在使用EWS升级一个使用WebDAV查询Exchange Server 2003邮箱的应用程序,新版本将适用于Exchange Server 2010 SP2。
我想排除包含以下搜索词的主题的电子邮件项目:"脂肪;分配;沙箱:作业"
我看了看MSDN库:通过使用EWS管理的API搜索邮箱中的项目,并发现如何过滤收件人,并且电子邮件有附件,但现在我需要更进一步,只阅读没有上述主题的电子邮件(4个不同的字符串排除)
下面是我试过的代码:
searchFilterCollection.Add(new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false)));
searchFilterCollection.Add(new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.HasAttachments, true)));
searchFilterCollection.Add(new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.ContainsSubstring(EmailMessageSchema.Subject, "FATS;Assignment;Sandbox: Assignment")));
但是我知道(最后一项)只会找到包含这些术语的项目,请问我如何使用搜索过滤器排除这些术语?
我在MSDN库上找到了答案:过滤不使用EWS管理的API:
我必须使用搜索过滤器。不是对象:
searchFilterCollection.Add(new SearchFilter.Not(new SearchFilter.ContainsSubstring(ItemSchema.Subject, "FATS")));
然后我将它添加到集合中:
searchFilterCollection.Add(new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false)));
searchFilterCollection.Add(new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.HasAttachments, true)));
searchFilterCollection.Add(new SearchFilter.Not(new SearchFilter.ContainsSubstring(ItemSchema.Subject, "FATS")));
// add all to the collection...
SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection.ToArray());