Question

In EWS, the EmailMessage has a sender (emailMessage.getSender()) and may has attachments (emailMessage.getAttachments()).

These attachments can be FileAttachment (for files) or ItemAttachment (for attached email).

There is a lot of information on this item attachment such as :

But how to find the sender of this attached email ?

Edit : Using EWS Java API 1.1.5 http://archive.msdn.microsoft.com/ewsjavaapi/Release/ProjectReleases.aspx?ReleaseId=5754

Was it helpful?

Solution 2

Following the SliverNinja response, I tried to retrieve the item as an email message. Using EWS with Java, you have to cast the item ItemAttachment as EmailMessage like this:

Item item = ((ItemAttachment) attachment).getItem();
if (item instanceof EmailMessage) {
    String sender = ((EmailMessage)item).getSender().getAddress();
}

The item can also be cast as Appointment or Contact or Task or ContactGroup.

Edit : Another way to get the sender is

((EmailMessage) item).getFrom().getAddress();

This looks like to do the same

OTHER TIPS

In c# - you could access the ItemAttachment.Message and then Message.Sender. Once you have the sender, you can retrieve Sender.Mailbox for accessing the Mailbox.EmailAddress. Maybe you can convert this to something similar for java.

ItemAttachment itemAttachment = attachment as ItemAttachment;
itemAttachment.Load();
Sender sender = itemAttachment.Message.Sender;
Mailbox mailbox = sender.Mailbox;
string email = mailbox.EmailAddress;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top