gmail中没有正确显示内联Rails附件 [英] Rails attachments inline are not shown correctly in gmail

查看:113
本文介绍了gmail中没有正确显示内联Rails附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以指出我的问题吗?

Can anyone point me to the problem?

我在我的rails 3.1应用程序邮件程序中使用内联附件。这封信还包含存储在亚马逊W3服务器上的图片。

I'm using inline attachments in my rails 3.1 application mailer. The letter also contains images which are stored at amazon w3 servers.

问题在于gmail不能正确显示字母。我在信中有内联附件。但Gmail将这些文件显示为附件。这封信还包含一个附带的HTML页面,其中包含该信件本身。
所有的gmail显示都是一组符号,我认为它是一个附加图像的base64版本。

The problem is that gmail doesn't display the letter correctly. I have inline attachments in the letter. But Gmail shows these files as attached ones. The letter also contains an attached html page which contains the letter itself. All gmail displays is a set of symbols which i suppose to a base64 version of one of the attached images.

查看屏幕截图。

由于缺乏必要的评分,我无法发布图片,所以我发布了它这里

I can't post the image due to the lack of necessary amount of rating so i posted it here.

以下是我的邮件中的代码:

Here is the code in my mailer:

attachments.inline['blank'] = File.read("#{Rails.root.to_s + '/app/assets/images/blank_500x500.png'}")
attachments.inline['discount-deal-triangle'] = File.read("#{Rails.root.to_s + '/app/assets/images/discount-deal-triangle.png'}")
mail(:to => @subscriber.email, :subject => subject)



And here is the code in the view file:

-if @image_url
  = image_tag( attachments['offer_image'].url, :id => 'offer_image', :width => "320", :height => "320")
-elsif @offer.image.nil?
  = image_tag( attachments['blank'].url, :id => 'offer_image', :width => "320", :height => "320")

我省略了细节以简化操作。

I have omitted the details to make it simpler.

我是什么做错了?

推荐答案

毕竟我找到了解决方案:您需要做的就是设置mime类型和编码

After all i found a solution: all you need to do is set the mime-type and encoding of the attachment.

attachments.inline['blank'] = {
                                :data => File.read("#{Rails.root.to_s + '/app/assets/images/blank_500x500.png'}"),
                                :mime_type => "image/png",
                                :encoding => "base64"
                              }
attachments.inline['discount-deal-triangle'] = {
                                :data => File.read("#{Rails.root.to_s + '/app/assets/images/discount-deal-triangle.png'}"),
                                :mime_type => "image/png",
                                :encoding => "base64"
                              }

这对我来说是个诀窍。

这篇关于gmail中没有正确显示内联Rails附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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