C#学习教程:searchFilter无法与EWSFindItems方法调用一起正常工作我连接服务和打开邮箱都没有问题。问题是我的searchFilter被忽略,所有电子邮件都被请求返回EWS。这是我的代码:staticvoidMain(string[]args){ServicePointManager.ServerCertificateValidationCallback=CertificateValidationCallBack;//创建一个代表所需邮箱的对象Mailboxmb=newMailbox(@"bbtest@bocuk.local");//查找正文中包含“移动报告”的所有项目。//stringqstring="Body:"movereports"";//确定要返回的项目属性。//view.PropertySet=newPropertySet(BasePropertySet.IdOnly,//ItemSchema.Subject);//创建一个指向收件箱的文件夹对象foldFolderIdfid=newFolderId(WellKnownFolderName.Inbox,mb);//这将使用您的服务实例绑定您要查找的邮箱Folderinbox=Folder.Bind(service,fid);列表searchFilterCollection=newList();searchFilterCollection.Add(newSearchFilter.SearchFilterCollection(LogicalOperator.And,newSearchFilter.IsEqualTo(EmailMessageSchema.IsRead,false)));searchFilterCollection.Add(新的SearchFilter.SearchFilterCollection(LogicalOperator.And,newSearchFilter.IsEqualTo(EmailMessageSchema.HasAttachments,true)));searchFilterCollection.Add(newSearchFilter.Not(newSearchFilter.ContainsSubstring(ItemSchema.Subject,"FATS")));searchFilterCollection.Add(newSearchFilter.Not(newSearchFilter.ContainsSubstring(ItemSchema.Subject,"Assignment")));searchFilterCollection.Add(newSearchFilter.Not(newSearchFilter.ContainsSubstring(ItemSchema.Subject,"Sandbox:Assignment")));SearchFiltersearchFilter=newSearchFilter.SearchFilterCollection(LogicalOperator.Or,searchFilterCollection.ToArray());ItemViewview=newItemView(100);字符串sAttachmentPath="C:\Dev\EWSHelloWorld\attachments\";//在收件箱中找到第一封有附件的电子邮件。这会导致对EWS的FindItem操作调用。FindItemsResults结果=service.FindItems(WellKnownFolderName.Inbox,searchFilter,view);foreach(EmailMessageemailinresults)//遍历所有的emails{System.Diagnostics.Debug.Write("在带有主题的消息中找到附件:"+email.Subject);....为简洁起见删除了代码!因此,根据我对searchFilter的理解,只应返回带有附件的消息。电子邮件未被阅读,不应以FATS或Sandbox:Assignment作为主题,但这不起作用,对EWS的请求只返回所有电子邮件。我做错了什么?菲利普,我开始调试你的代码,对你想要返回的内容感到有点困惑。在您的代码中,您在创建搜索过滤器时使用了OR运算符,但在文本中,您将所需的输出描述为仅应返回带附件的未读电子邮件,而不应将FATS或Sandbox:Assignment作为主题。我采用了您尝试过滤的参数并提出了以下过滤器,它将所有过滤器与在我的机器上工作的逻辑AND组合在一起:搜索过滤器集合。添加(新SearchFilter.IsEqualTo(EmailMessageSchema.IsRead,false));searchFilterCollection.Add(newSearchFilter.IsEqualTo(EmailMessageSchema.HasAttachments,true));searchFilterCollection.Add(newSearchFilter.Not(newSearchFilter.ContainsSubstring(EmailMessageSubstring(EmailMessageSubstring,"FATS")));searchFilterCollection.Add(newSearchFilter.Not(newSearchFilter.ContainsSubstring(EmailMessageSchema.Subject,"Assignment")));searchFilterCollection.Add(newSearchFilter.Not(newSearchFilter.ContainsSubstring(EmailMessageSchema.Subject,"Sandbox:Assignment")));FindItemsResultsresults=service.FindItems(WellKnownFolderName.Inbox,searchFilterCollection,newItemView(100));一些事情注意:我在运行测试的时候,如果我先过滤掉带附件的未读消息。然后我确认在添加主题过滤器时,返回的结果被进一步过滤。我希望这有助于帮助。以上就是C#学习教程的全部内容:searchFilter和EWSFindItems方法调用无法正常工作。如果对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
