回形针图像未显示在Action Mailer电子邮件中

时间:2019-09-03 16:38:58

标签: amazon-s3 ruby-on-rails-5 paperclip actionmailer

我正在编写一个非常简单的电子邮件模板,该模板发送带有嵌入式图像的HTML电子邮件。图像使用Paperclip gem存储在AWS S3中:

<%= image_tag @press_release.image.try(:attachment).try(:url, :preview), alt: 'zimplePR', style: 'width: 85%; max-height: 200px; object-fit: cover;' %>

在生产中,该image_tag助手在我的Web视图中充当了一种魅力,但是由于某些原因,我发送的电子邮件中未显示该助手。

我在某处读到它,也许是因为Paperclip的完整附件URL类似于//s3.amazonaws.com/...,并且在'http:'前面应该可以,但是仅在Gmail中有效,例如在Apple电子邮件中不起作用。 / p>

是否可以使用在所有电子邮件客户端中显示的Paperclip和beign将图像嵌入到ActionMailer模板中?

1 个答案:

答案 0 :(得分:0)

我发现了问题,该错误的原因是因为我没有指定附件的:http协议:

Class Image < ApplicationRecord
  has_attached_file :attachment,
                    :styles => {
                      :thumb   => ['80x80>', :png],
                      :preview => ['600x600>', :png]
                    },
                    :convert_options =>{
                      :thumb   => "-quality 80 -interlace Plane",
                      :preview => "-quality 80 -interlace Plane",
                    },
                    :default_url => 'images/missing_:style.png',
                    :s3_protocol => :https,
                    :s3_credentials => {
                      :bucket => Rails.application.credentials[:aws][:s3_bucket_production]
                    }
end