如何检索消息和任务主体 - Exchange Web服务 - Java

时间:2014-05-28 10:28:32

标签: java exchangewebservices independentsoft

我正在使用JWebServices创建一条消息,但即使成功检索到所有其他字段,body也没有。 message.getBody()返回null。以下是我随后称之为的两种方法。

private void createMessage(Service service) throws ParseException {
    try {
        Message message = new Message();
        message.setItemClass(ItemClass.MESSAGE);
        message.setSubject("Test");
        message.setBody(new Body("Body text"));
        message.getToRecipients().add(new Mailbox("John@mydomain.com"));
        message.getCcRecipients().add(new Mailbox("Mark@mydomain.com"));

        ItemId itemId = service.createItem(message,StandardFolder.SENT_ITEMS);
    } catch (ServiceException e) {
        System.out.println(e.getMessage());
        System.out.println(e.getXmlMessage());

        e.printStackTrace();
    }
}

private void listItemsInSent(Service service) throws ParseException {
    try {
        FindItemResponse response = service.findItem(StandardFolder.SENT_ITEMS);
        Message m = null;
        for (int i = 0; i < response.getItems().size(); i++) {
            m = (Message)response.getItems().get(i);
            System.out.println(m.getSubject());
            System.out.println(m.getItemClass());
            System.out.println(m.getLastModifiedTime());
            System.out.println(m.getBody());
            System.out.println(m.getBodyHtmlText());
            System.out.println(m.getBodyPlainText());
            System.out.println(m.getItemId());
            System.out.println(m.toString());
            System.out.println();
        }
    } catch (ServiceException e) {
        System.out.println(e.getMessage());
        System.out.println(e.getXmlMessage());

        e.printStackTrace();
    }
}

1 个答案:

答案 0 :(得分:2)

尝试替换

m = (Message)response.getItems().get(i);

m = service.getMessage(response.getItems().get(i).getItemId());