我需要获取所有具有特定类别名称的电子邮件,我该怎么做?
现在我有这个:
var col = new List<SearchFilter>();
col.Add(new SearchFilter.ContainsSubstring(ItemSchema.Categories, "Processed"));
var filter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, col.ToArray());
FindItemsResults<Item> findResults = service.FindItems(
WellKnownFolderName.Inbox,
filter,
new ItemView(10)
);
但是这给了我Microsoft.Exchange.WebServices.Data.ServiceResponseException
{"The Contains filter can only be used for string properties."}
我该怎么做?
答案 0 :(得分:3)
AFAIK自Exchange 2010起,类别是一个多值字段,因此它不适用于搜索过滤器。但是,您可以使用AQS搜索类别。以下代码应该可以解决问题。
ExchangeService service = GetService();
var iv = new ItemView(1000);
string aqs = "System.Category:Processed";
FindItemsResults<Item> searchResult = null;
do
{
searchResult = service.FindItems(WellKnownFolderName.Inbox, aqs, iv);
foreach (var item in searchResult.Items)
{
Console.WriteLine(item.Subject);
}
iv.Offset += searchResult.Items.Count;
} while (searchResult.MoreAvailable == true);