How to get recipients addresses as String in JavaMail?
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.
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());
}
精彩评论