Expand my Community achievements bar.

AEM 6.4 - How to have multiple To recipients in email template.

Avatar

Level 1

How to have multiple To recipients in my Email ?

Currently String[] sends mail one by one.

But i want the email to be sent having multiple people in To .

How can i achieve it ? I tried ACS commons API with these options. nothing worked. Got Invalid Recipients error.  I referred this documentation.

Email API

String recipients = "email@ab.com,email2@ab.com";

emailService.sendEmail(htmlEmailTemplatePath, emailParams, attachments, recipients)

String recipients = "email@ab.com;email2@ab.com";

emailService.sendEmail(htmlEmailTemplatePath, emailParams, attachments, recipients)

String recipients = "To : email@ab.com"+"\n"+"To : email2@ab.com";

emailService.sendEmail(htmlEmailTemplatePath, emailParams, attachments, recipients)

I tried various options like declaring recipients in above format but nothing worked. I want something like this in my email.

To : email@ab.com, email2@ab.com Sub : Sample Subj Email Body....

4 Replies

Avatar

Level 1

Hello Mohammad,

In the API you have referenced the 'recepients' argument is a variable array of recipients email addresses. Therefore, you would need to define it in the following format:

String[] recipients = { "recipient1@example.com", "recipient2@example.com" };

Hope this helps!

Avatar

Level 1

Hi,

Thanks for the response. By declaring String[] recipients = { "recipient1@example.com", "recipient2@example.com" };

two emails will get generated right ?

First Email will have recipient1@example.com in To field and Second Email will have recipient2@example.com in To field. How can i generate single email having both recipient 1 and recipient 2 in To field ?

Avatar

Level 1

I am not sure if that can be done with the ACS commons bundle but what you can do (more of a workaround) is to have the recipient list in the body of the template to let each recipient know about who else the email was sent to (assuming that's the use case).

You can also leverage the ACS commons chat support from the below link and bring this up as a potential enhancement with them:

acsaemhttps://gitter.im/Adobe-Consulting-Services/acs-aem-commons

Avatar

Level 10

Write a custom AEM Service that uses Java MAIL API.