Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send an image in an email with Grails

I am using the Grails mail plugin to send emails and I want to send images in the body of the email, not as attachment. What I want is for images to be shown in the email body itself, as in newsletters. I tried:

img style="display:block; height:100px; width:100; " alt="candle"
src="http://www.xyz.com//Candle_4.jpg">

but it is being displayed as-is.

I also tried using the wikimedia format:

[[:File:Example.jpg]]<br/>
[[Special:FilePath/Example.jpg]]

but again, both seem to link to external.

What am I doing wrong?

This is the email template I am using:

<img src="cid:springsourceInlineImage" /> Dear [username],<br/>
Thank you for shopping with us.<br/>
You have placed a new order with following details.<br/>
[details]<br/>
Happy shopping!

But, if I want to put 10 images in my template, how would I do that?

like image 439
zade Avatar asked Dec 12 '22 02:12

zade


1 Answers

You have to do three things

  1. Declare mail as multipart
  2. Attach your image as inline image
  3. Reference you inline image from your mail template

According to this mailing list thread it should work like this:

sendMail{
    multipart true
    to "[hidden email]"
    subject "Subject goes here"
    html  g.render( template: '/emails/mailTemplate')
    inline 'springsourceInlineImage', 'image/jpg', new File('./web-app/images/springsource.png')
}

In your template you could refer the image like this

<img src="cid:springsourceInlineImage" />

Hope that helps.

like image 116
aiolos Avatar answered Jan 27 '23 18:01

aiolos