I want to send message to multiple Recipients using following method ::
message.addRecipient(Message.RecipientType.TO, String arg1);
OR
message.setRecipients(Message.RecipientType.TO,String arg1);
But one confusion is that in Second arguement, How to pass multiple addresses like :
message.addRecipient(Message.RecipientType.CC, "abc@abc.com,abc@def.com,ghi@abc.com");
OR
message.addRecipient(Message.RecipientType.CC, "abc@abc.com;abc@def.com;ghi@abc.com");
I can send message using alternate methods too, but want to know the purpose of above method. If i cant use it(as till now i haven't got any answer for above requirement) then what is the need for this method to be in mail API.
You can have multiple addresses separated by comma
If you invoke
addRecipient
multiple times it will add the given recipient to the list of recipients of the given time (TO, CC, BCC)For example:
Will add the 3 addresses to CC
If you wish to add all addresses at once you should use
setRecipients
oraddRecipients
and provide it with an array of addressesYou can also use
InternetAddress.parse
to parse a list of addressesIf you want to send as Cc using MimeMessageHelper
Same you can use to add multiple recipient.
So ... it took many months, but still ... You can send email to multiple recipients by using the ',' as separator and
is ok. At least in JavaMail 1.4.5
InternetAddress.Parse is going to be your friend! See the worked example below:
If strict is true, many (but not all) of the RFC822 syntax rules for emails are enforced.
Parse comma/space-separated list. Cut some slack. We allow spaces seperated list as well, plus invalid email formats.