How to send an email with attachments?
Together with other input text, from the form, I have to send an email and add the possibility of attaching a file coming from the DAM. How can I do it?
Together with other input text, from the form, I have to send an email and add the possibility of attaching a file coming from the DAM. How can I do it?
Hi @vodjakxa ,
Using ACS AEM Commons EmailService, we can simplify the email-sending process in AEM as a Cloud Service (AEMaaCS) while maintaining best practices. The EmailService provided by ACS Commons allows us to send emails with dynamic variables and attachments easily. Read more: https://adobe-consulting-services.github.io/acs-aem-commons/features/e-mail/email-api/index.html
The sendMail(..) method now supports the following signature:
public List<String> sendEmail(String templatePath, Map<String, String> emailParams, Map<String, DataSource> attachments, String... recipients)
public List<InternetAddress> sendEmail(String templatePath, Map<String, String> emailParams, Map<String, DataSource> attachments, InternetAddress... recipients)
E-mail attachments can be passed in via the attachments parameter.
...
Map<String, DataSource> attachments = new HashMap<>();
String attachmentContentsAsString = "This text should be in the attache txt file."
attachments.put("attachment1.txt", new ByteArrayDataSource(attachmentContentsAsString, "text/plain"));
...
List<String> participantList = emailService.sendEmail(htmlEmailTemplatePath, emailParams, attachments, recipients);
Best regards,
Kostiantyn Diachenko.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.