Question

How can I specify the SearchFilter with Java EWS library to fetch mails containing defined subject line?

Thanks in advance.

Was it helpful?

Solution

Assuming you mean the library created by Microsoft, here is an example directly from the Getting started with EWS Java API.rtf included in the download:

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.
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top