It's all about the answers!

Ask a question

How to send emails to multiple recipients using sendMail service method


Martin Wassermann (13864044) | asked Oct 01 '13, 7:19 a.m.
edited May 27 '15, 3:38 a.m. by Piotr Aniola (3.7k1635)
Hi,

I send mails from my precondition with the service method

    sendMail(MailSender sender, String toAddress, String subject, String msg, String cc)

For only one recipients it works fine, but I fail to use this method to send mails to multiple recipients. I tried it with comma separated mail addresses (with and without spaces e,g, address1@mail.de,adress2@mail.de) and with semicolon separated mail addresses. But every time I receive the following exception

javax.mail.internet.AddressException: Illegal address in string ``address1@mail.de,adress2@mail.de''

So, how must the toAdress parameter be formatted so that the mail will be send to multiple recipients?

Thanks and regards
Martin

Accepted answer


permanent link
Piotr Aniola (3.7k1635) | answered Oct 01 '13, 7:21 a.m.
edited May 27 '15, 3:40 a.m.
Hello,

As a workaround:
you can chop down the string that contains multiple email addresses so that each piece contains only one email address. Then you can invoke the sendMail service method once for each email address.
Martin Wassermann selected this answer as the correct answer

Comments
Martin Wassermann commented Oct 01 '13, 7:31 a.m.

I think that will work too. If I find no other solution I will try to send a mail for each recipient. But I prefer to send one mail to multiple recipients.

Your answer


Register or to post your answer.