Question

in grails-mail plugin you need do define your inline image data in your service, assuming you are using grails mail from a service.

you do this like so in your service.groovy

inline 'header', 'image/jpg', new File('./web-app/images/mailAssets/alert_header_pre.png')

inside your service definition, lets say:

def mailService
def contactUser(userName, email) {
    mailService.sendMail {
        multipart true
        to email
        from "marc.heidemann@live.de"
        subject "Hello from grails-mail"
        text "Hallo from grails-mail multipart text modus"
        html view:"/alert/test", model:[name:userName]
        inline 'header', 'image/jpg', new File('./web-app/images/mailAssets/alert_header_pre.png')
        inline 'footer', 'image/jpg', new File('./web-app/images/mailAssets/suchebottomre.gif')
    }
}

for now, the app is rendering the footer and the header image, Ok.

alright, now the plan of the planners of this project is to render profile pictures from database (about 15.000 users) in their emails - can and if then how can this be achieved without declaring every user's profile picture inside the service.groovy? Furthermore those pictures are stored outside of my app at amazon s3. might this be a boundary of mail plugin or is it possible to get this working? What would you offer those planning and creative guys as an alternative if it is not possible to do so? any opinions are welcome.

Was it helpful?

Solution

  1. Loop through your users.
  2. Get the corresponding picture from S3 using the grails-aws-plugin.
  3. Insert picture into email
  4. Send mail using the mail-plugin

That way you don't have to declare it in the service. You can download the pictures from S3 to use them as inline pictures or you could use a url provided by S3.

To access the file for inline usage:

def file = aws.s3().on(bucket).get(name, path)

To get a public url:

def url = aws.s3().on(bucket).url(name, path)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top