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

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

问题描述

谁能指出问题所在?

我在我的 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.

这是我邮件中的代码:

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-type和编码.

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

这对我有用.

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

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