Send an image in an email with Grails

后端 未结 3 1963
攒了一身酷
攒了一身酷 2020-12-30 16:28

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 bo

3条回答
  •  渐次进展
    2020-12-30 17:19

    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

    
    

    Hope that helps.

提交回复
热议问题