EWS获取具有指定主题行的邮件

时间:2014-02-24 07:54:19

标签: java exchangewebservices ewsjavaapi

如何使用Java EWS库指定SearchFilter以获取包含已定义主题行的邮件?

提前致谢。

1 个答案:

答案 0 :(得分:4)

假设您的意思是Microsoft创建的库,下面是直接来自下载中包含的 EWS Java API.rtf 入门的示例:

public void findItems()
{
ItemView view = new ItemView(10);
view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
view.setPropertySet(new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject,
        ItemSchema.DateTimeReceived));


FindItemsResults<Item> findResults = service.findItems(WellKnownFolderName.Inbox, new SearchFilter.SearchFilterCollection(
LogicalOperator.Or, new SearchFilter.ContainsSubstring(ItemSchema.Subject, "EWS"), 
new SearchFilter.ContainsSubstring(ItemSchema.Subject, "API")),view);

System.out.println("Total number of items found: " + findResults.getTotalCount());

for (Item item : findResults)
    {
            System.out.println(item.getSubject());
            System.out.println(item.getBody());
            // Do something with the item.
    }
}