How to attach multiple attachments with mail in grails?

For sending mail you can use Asynchronous Mail Plugin.

1. Install Asynchronous Mail Plugin :

Dependency:  compile “:asynchronous-mail:1.2″

2. Usage :

Add following:

import grails.plugin.asyncmail.AsynchronousMailService

     AsynchronousMailService asynchronousMailService

3. In your method to add multiple attachment create map as shown below,

Map<String,ByteArrayOutputStream> attachments = new HashMap<String,ByteArrayOutputStream>();

ByteArrayOutputStream bytes0,bytes1,bytes2; // attachments

attachments.put(‘key0′,bytes0);

attachments.put(‘key1′,bytes1);

attachments.put(‘key2′,bytes2);

asynchronousMailService.sendMail {
multipart true
to emailID
subject emailSubject
html emailBodyContent
attachBytes “Approval”, “application/pdf”, attachments

}

attachBytes is used to attach attachments.


ProsperaSoft offers Grails development solutions. You can email at info@prosperasoft.com to get in touch with ProsperaSoft Grails experts and consultants.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>