[英]Rails action_mailer config not working in production
我正在嘗試使用Rails 4.1.0設置action_mailer來發送電子郵件。
在我的config / environments / {env} .rb中,我有:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.mandrillapp.com',
port: 587,
domain: 'domain.com',
authentication: 'login',
user_name: 'email@domain.com',
password: 'pass',
enable_starttls_auto: true }
它在開發中工作正常,但在產品中嘗試連接到本地主機。
m = Mail.new
m.delivery_method
=> #<Mail::SMTP:0xbd79fdac @settings={:address=>"localhost", :port=>25, :domain=>"localhost.localdomain", :user_name=>nil, :password=>nil, :authentication=>nil, :enable_starttls_auto=>true, :openssl_verify_mode=>nil, :ssl=>nil, :tls=>nil}>
但是當我執行“ puts Rails.application.config.action_mailer”時,我得到了正確的配置
{:raise_delivery_errors=>false, :default_url_options=>{:host=>"domain.com"}, :delivery_method=>:smtp, :smtp_settings=>{:address=>"smtp.mandrillapp.com", :port=>587, :domain=>"domain.com", :authentication=>"login", :user_name=>"email@domain.com", :password=>"password", :enable_starttls_auto=>true}, :assets_dir=>"xxx", :javascripts_dir=>"xxx", :stylesheets_dir=>"xxx", :asset_host=>nil, :relative_url_root=>nil}
任何想法?
默認情況下,Mail gem不會使用您的ActionMailer配置。 ActionMailer使用郵件,但是這些配置設置僅在您通過ActionMailer發送郵件時適用。
如果它在您的開發人員模式下工作,那么您肯定已經在development.rb環境文件或特定於環境的初始化程序中分別配置了Mail gem。
我忘了我的development.rb中有這個配置
Mail.defaults do
delivery_method Rails.configuration.action_mailer.delivery_method, Rails.configuration.action_mailer.smtp_settings
end
您需要在production.rb
文件上為default_url_options
哈希添加host
選項,如下所示:
config.action_mailer.default_url_options = { :host => ENV['HOST_DEFAULT_URL'],
only_path: false }
這應該夠了吧。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.