我正在使用Exchange Web服务搜索电子邮件收件箱(在Exchange 2010上)。
在我的SearchFilterCollection中,我想要包含电子邮件的From.Address
属性,因为我只想检索包含某个域的电子邮件(例如@ domain.co.uk)
这是我的代码:
SearchFilter.SearchFilterCollection searchFilterCollection = new SearchFilter.SearchFilterCollection(LogicalOperator.And);
searchFilterCollection.Add(new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
searchFilterCollection.Add(new SearchFilter.IsEqualTo(EmailMessageSchema.HasAttachments, true));
// **** PROBLEM HERE ON BELOW LINE****
searchFilterCollection.Add(new SearchFilter.ContainsSubstring(EmailMessageSchema.From, "@domain.co.uk")); //
// add the exceptions
for (int iEx = 0; iEx < e2c.emailExceptions.Count; iEx++)
{
searchFilterCollection.Add(new SearchFilter.Not(new SearchFilter.ContainsSubstring(EmailMessageSchema.Subject, e2c.emailExceptions[iEx])));
}
ItemView view = new ItemView(100);
view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
// Find the first email message in the Inbox that has attachments. This results in a FindItem operation call to EWS.
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Inbox, searchFilterCollection, view);
有没有一种方法可以在SearchFilter中包含电子邮件地址?
答案 0 :(得分:2)
我前几天创建了一个搜索文件夹,它使用How to: Work with search folders by using EWS in Exchange主题中的示例执行相同操作:
// Create a search filter to express the criteria
// for the folder.
EmailAddress manager = new EmailAddress("sadie@contoso.com");
SearchFilter.IsEqualTo fromManagerFilter =
new SearchFilter.IsEqualTo(EmailMessageSchema.Sender, manager);
现在这是使用Sender属性,而不是From属性。我认为你可以简单地替换另一个,但我没有测试以确定。