【问题标题】:Paperclip image doesn't show in Action Mailer email回形针图像未显示在 Action Mailer 电子邮件中
【发布时间】:2020-01-06 14:22:50
【问题描述】:

我正在编写一个非常简单的电子邮件模板,用于发送带有嵌入图像的 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 电子邮件。

有没有办法使用 Paperclip 将图像嵌入到 ActionMailer 模板中并显示在所有电子邮件客户端中?

【问题讨论】:

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


    【解决方案1】:

    我发现了问题,这个错误的原因是因为我没有指定附件的 :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 
    

    【讨论】:

      猜你喜欢
      • 2014-04-06
      • 1970-01-01
      • 2011-10-17
      • 2013-05-21
      • 1970-01-01
      • 2013-04-14
      • 2016-11-27
      • 2015-08-23
      • 1970-01-01
      相关资源
      最近更新 更多