Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get sender email address with EWS Java API

I am using EWS Java API 1.1.5. I am trying to get the email sender as follows:

ItemView view = new ItemView(10);
FindItemsResults<Item> findResults = service.findItems(
    WellKnownFolderName.Inbox, view);
    for (Item item : findResults.getItems()) {
        if (item instanceof EmailMessage) {
            String senderEmail = ((EmailMessage) item).getSender().getAddress();
            System.out.println("Sender Email: " + senderEmail);
        }
    }
);

But it always returns null. I also tried the following:

String senderEmail = ((EmailMessage) item).getFrom().getAddress();

But it also returns null. I can see that the email contains sender like:

Test User <[email protected]> 

It appears in the message and also when replying to the email.

Please advise how to fix this issue.

like image 990
Mahmoud Saleh Avatar asked Nov 05 '12 11:11

Mahmoud Saleh


1 Answers

found the solution, i have to use item.load(); before getting the sender email address.

like image 162
Mahmoud Saleh Avatar answered Oct 21 '22 08:10

Mahmoud Saleh