使用 Grails 在电子邮件中发送图像 [英] Send an image in an email with Grails

查看:18
本文介绍了使用 Grails 在电子邮件中发送图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Grails 邮件列表线程它应该像这样工作:

sendMail{多部分真到[隐藏的电子邮件]"主题主题在这里"html g.render( 模板:'/emails/mailTemplate')内联 'springsourceInlineImage', 'image/jpg', new File('./web-app/images/springsource.png')}

在您的模板中,您可以像这样引用图像

希望有所帮助.

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?

解决方案

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.

这篇关于使用 Grails 在电子邮件中发送图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆