Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7633065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:46:51+00:00 2026-05-31T06:46:51+00:00

I am using grails Async Mail plugin to send emails with attachments in my

  • 0

I am using grails Async Mail plugin to send emails with attachments in my app. to achieve that I have written following code

def sendEmail = {
    def documentsInstances = Documents.getAll(params.list('ids[]'))
    def s3Service = new AmazonS3Service()
    documentsInstances.each(){documentsInstance->
            asyncMailService.sendMail {
                multipart true
                to documentsInstance.author.emailAddress
                subject 'Test';
                html '<body><u>Test</u></body>';
                attachBytes documentsInstance.filename , 'text/plain', s3Service.getBytes(session.uid,documentsInstance.filename);
            }
    }//

}

Now the code above works pretty much correctly but it sends an email per attachment, I am not sure how can I move this loop inside send mail so that I can send multiple attachments in an email.

Also is there a way to send an email so that I don’t have to load a whole file in byte[]?

I am using JetS3t for access to Amazon S3 and I tried “attach” method with

new InputStreamResource(s3Obj.getDataInputStream()) ie

attach documentsInstance.filename , 'text/plain', new InputStreamResource(s3Obj.getDataInputStream());

but I am getting

"Passed-in Resource contains an open stream: invalid argument. JavaMail requires an InputStreamSource that creates a fresh stream for every call"

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:46:52+00:00Added an answer on May 31, 2026 at 6:46 am

    You need your loop inside the email:

    def sendEmail = {
        def documentsInstances = Documents.getAll(params.list('ids[]'))
        def s3Service = new AmazonS3Service()
        asyncMailService.sendMail {
            multipart true
            to documentsInstance.author.emailAddress
            subject 'Test';
            html '<body><u>Test</u></body>';
    
            // loop over attachments
            documentsInstances.each{ documentsInstance->
                attachBytes documentsInstance.filename , 'text/plain', s3Service.getBytes(session.uid, documentsInstance.filename);
            }
        }
    }
    

    This should attach multiple files.

    If it throws an error about not being able to find an attachBytes method, you might need to explicitly call owner.attachBytes instead, which should refer to the outer sendMail closure.


    Update based on comments:

    The Async plugin looks like it defers to the normal mail plugin. The normal mail plugin’s docs describes how to use multiple attachments.

    This would look something like:

       // loop over attachments
        documentsInstances.each{ documentsInstance->
            attach documentsInstance.filename , 'text/plain', s3Service.getBytes(session.uid, documentsInstance.filename);
          //^^^^^^ Notice, just 'attach', not 'attachBytes'
        }
    

    I don’t know the S3 plugin you are using, but if there is a way to retrieve an InputStreamSource from it, it appears that you can stream the bytes directly to the mail plugin, instead of loading them into memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Grails 2.0.0 project that was created using grails create-app . In
I'm using Grails and I have a local-plugin (that I wrote) that I'm using
I'm using Grails 1.3.7. I have some code that uses the built-in base64Encode function
I'm using Grails Mail plugin and trying to send email and keep getting: Error
Using Grails and CXF, I have published a small web service that looks like
I face a problem using Grails 2 submitToRemote tag. The following code is what
Background: we have a Grails 1.3.7 app and are using Liquibase to manage our
We're developing an app (using Grails Spring Security (formerly Acegi)) in which we'll have
I'm using: Grails xfire plugin and I created the service mobile containing the following
I am currently using Grails Mail 1.0 plugin in my project. I used it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.