config.action_mailer.asset_host不提供来自云端CDN的图像

问题描述 投票:1回答:1

我有一个CloudFront CDN服务于我的rails资产。当查看通过Web浏览器提供的资产来源时,它会正确指向我的CDN。但是,Action Mailer在为其资产提供服务时未使用此路径。

为什么会这样?

这是我的环境/production.rb文件:

 config.action_mailer.perform_caching = false
  config.action_mailer.default_url_options = { host: 'localhost' }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = false
  config.action_mailer.smtp_settings = {
      :address => "email-smtp.us-east-1.amazonaws.com",
      :port => 587,
      :user_name => Figaro.env.smtp_username, #Your SMTP user
      :password => Figaro.env.smtp_password, #Your SMTP password
      :authentication => :login,
      :enable_starttls_auto => true
  }
  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
  config.action_controller.asset_host = Figaro.env.cloudfront_endpoint
  config.action_mailer.asset_host = Figaro.env.cloudfront_endpoint
ruby-on-rails ruby ruby-on-rails-5 amazon-cloudfront actionmailer
1个回答
1
投票

似乎您没有为config.action_mailer.default_url_options设置正确的值。

This is what the docs says:

与控制器不同,邮件程序实例没有关于传入请求的任何上下文,因此您需要自己提供:host参数。

由于:host通常在整个应用程序中是一致的,因此您可以在config/application.rb中进行全局配置。>

应该是:

config.action_mailer.default_url_options = { host: Figaro.env.cloudfront_endpoint }

注意:请确保您在邮件视图/模板中使用image_url而不是image_path

© www.soinside.com 2019 - 2024. All rights reserved.