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

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

问题描述

我正在使用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">

但正在按原样显示。

我还尝试使用wikimedia格式:

I also tried using the wikimedia format:

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

但是,链接到外部。

我做错了什么?

这是电子邮件模板我正在使用:

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!

但是,如果我想在我的模板中放置10个图像,我该怎么做? p>

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

推荐答案

你必须做三件事


  1. 将邮件声明为多部分

  2. 将图像作为内联图像附加

  3. 从邮件模板中引用内联图像

根据这个邮件列表线程应该这样工作:

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" />

希望有所帮助。

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

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