views:

19

answers:

1

I have a piece of code VERY similar to this one http://java.sun.com/developer/onlineTraining/JavaMail/contents.html#JavaMailFetching

I the difference is that I need to get the "TO" addresses as a String. I can't find in the API how to get the "TO" recipients as String for each Message.

Can anyone guide me on how to do this? At least a link where someone has already done it.

Thanks in advance

+1  A: 

Once you have a Message object (in their example it's "message[0]" since they have an array of Messages), you can do something like

List<String> toAddresses = new ArrayList<String>();
Address[] recipients = message.getRecipients(Message.RecipientType.TO);
for (Address address : recipients) {
    toAddresses.add(address.toString());
}
JacobM