开发者

How to get recipients addresses as String in JavaMail?

开发者 https://www.devze.com 2022-12-25 03:34 出处:网络
I have a piece of code VERY similar to this one http://java.sun.com/developer/onlineTraining/JavaMail/contents.html#JavaMailFetching

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());
}
0

精彩评论

暂无评论...
验证码 换一张
取 消