2

受信トレイのメッセージのすべての本文をきれいに印刷するプログラムを作成しようとしていますが、Web サービスを交換することは困難です。メッセージの本文以外のすべてに簡単にアクセスできるようです。これは私が今していることです

static final int SIZE = 10;
public static void main(String [] args) throws Exception {
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);

ExchangeCredentials credentials = new WebCredentials("USERNAME","PASS");
service.setCredentials(credentials);
service.setUrl(new URI("https://MY_DOMAIN/ews/exchange.asmx"));

ItemView view = new ItemView (SIZE);
FindItemsResults<Item> findResults = service.findItems(WellKnownFolderName.Inbox, view);
System.out.println(findResults.getItems().size() + "Messages");


for (int i = 0; i < SIZE; ++i) {
    try {
        Item item = findResults.getItems().get(i);
    System.out.println("SUBJECT: " + item.getSubject());
    System.out.println("TO: " + item.getDisplayTo());
    System.out.println("BODY: " + item.getBody().toString());


    } catch (IndexOutOfBoundsException e) {
        break;
    }


}

もちろん、資格情報とドメインをコードに合わせて入力しています。これを実行すると、このメッセージが表示されます。

Exception in thread "main" microsoft.exchange.webservices.data.ServiceObjectPropertyException: You must load or assign this property before you can read its value.
    at microsoft.exchange.webservices.data.PropertyBag.getPropertyValueOrException(Unknown Source)
    at microsoft.exchange.webservices.data.PropertyBag.getObjectFromPropertyDefinition(Unknown Source)
    at microsoft.exchange.webservices.data.Item.getBody(Unknown Source)
    at Main.main(Main.java:26)

26 行目は、ボディを印刷しようとする行です。私は何を間違っていますか?

4

2 に答える 2