Using javax.mail to send to multiple recipients

I have the following ...

msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to)); 

Which works fine, but when I try to add this several times (with different variables for to ), it only sends the last statement. I also tried sending something like email1@gmail.com : email2@gmail.com as the variable to , but this will throw an error.

Does anyone have any suggestions on how I sent mail to multiple recipients using ONLY one email and not multiple email messages using javax.mail ?

+4
source share
2 answers

msg.setRecipients() takes an array of addresses as the second parameter.

+8
source

Use message subclass - MimeMessage. This implements the setRecipients(Message.RecipientType type, Address[] addresses) method setRecipients(Message.RecipientType type, Address[] addresses) .

In addition, you can choose which specific message you need to use: IMAPMessage, POP3Message, SMTPMessage .

+1
source

All Articles