0

I need your help in Fetching TO information from the mail using Java.

I have got C# code, but dont know how to write into Java. For reference I am placing C# code below here.

Recipients = ((Microsoft.Exchange.WebServices.Data.EmailAddressCollection)item.Item[EmailMessageSchema.ToRecipients]).Select(recipient => recipient.Address).ToArray().

It would be great if I can see this code in java.

Thanks in advance.

LuCio
  • 5,055
  • 2
  • 18
  • 34
Karthik tn
  • 19
  • 8

1 Answers1

2

If the only property you want to read is ToRecipients (precisely EmailMessageSchema.ToRecipients) you can do this like that:

    PropertySet propertySet = new PropertySet(EmailMessageSchema.ToRecipients);
    EmailMessage email = EmailMessage.bind(service, new ItemId(emailId), propertySet);
    EmailAddressCollection toRecipients = email.getToRecipients();
    for (EmailAddress toRecipient : toRecipients) {
        String address = toRecipient.getAddress();
        // go on
    }

Providing a propertySet like above will enusre that the property ToRecipients will be the only one set on the returned EmailMessage. Thus the call isn't that expensive like:

EmailMessage email = EmailMessage.bind(service, new ItemId(emailId));

This would return an EmailMessage with all first class properties set. ToRecipients is a member of them.

EDIT:
Caution: There is also the property ItemSchema.DisplayTo. So asking in the title of the question for "To" is ambiguous.

LuCio
  • 5,055
  • 2
  • 18
  • 34