How to get recipient addresses as String in JavaMail?

I have a code snippet very similar to this http://java.sun.com/developer/onlineTraining/JavaMail/contents.html#JavaMailFetching

I mean, I need to get the "TO" addresses as a string. I can’t find in the API how to get β€œTO” recipients as a String for each message.

Can someone visit me how to do this? At least a link where someone has already done this.

+4
source share
1 answer

Once you have a Message object (in their example, this is β€œ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()); } 
+8
source

Source: https://habr.com/ru/post/1305779/


All Articles