EWS:FindItem请求异常

时间:2016-07-15 12:19:51

标签: java exchangewebservices

我正在尝试实现将使用EWS协议与Mail服务器通信的Java客户端。所以我决定使用这个EWS API

现在我正在尝试从邮箱中获取项目,它运行良好,但是当我添加一些SearchFilter时,发生了异常:

microsoft.exchange.webservices.data.core.exception.service.remote.ServiceResponseException: Unsupported restriction in FindItem request
at microsoft.exchange.webservices.data.core.response.ServiceResponse.internalThrowIfNecessary(ServiceResponse.java:278)
at microsoft.exchange.webservices.data.core.response.ServiceResponse.throwIfNecessary(ServiceResponse.java:267)
at microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:165)
at microsoft.exchange.webservices.data.core.ExchangeService.findItems(ExchangeService.java:985)
at microsoft.exchange.webservices.data.core.ExchangeService.findItems(ExchangeService.java:1028)
at microsoft.exchange.webservices.data.core.ExchangeService.findItems(ExchangeService.java:1088)
at main.Main.findItems(Main.java:66)
at main.Main.<init>(Main.java:49)
at main.Main.main(Main.java:84)

这是我使用的代码,它是我从Github网站复制的代码:

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

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


    //MOOOOOOST IMPORTANT: load items properties, before
    service.loadPropertiesForItems(findResults, PropertySet.FirstClassProperties);
    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.
    }
}

由于

1 个答案:

答案 0 :(得分:1)

我找到了答案。

这是由电子邮件服务器引起的,它不支持查找项目的重新定位。