2012-06-28 10 views
6

の設定を無視します:Railsのactionmailerのは、私はそうのように私の<code>config/environment.rb</code>ファイルで私のactionmailerのコンフィグを入れenvironment.rbに

MyApp::Application.initialize! 
MyApp::Application.configure do 

    config.action_mailer.delivery_method = :smtp 
    config.action_mailer.smtp_settings = { 
     address: "smtp.elasticemail.com", 
     port: 2525, 
     domain: "myapp.com", 
     authentication: "plain", 
     user_name: "my_username", 
     password: "my_password", 
     enable_starttls_auto: true 
    } 

end 

私の理解では、これはすべての環境に適用する設定を構成するための正しい方法であるということです。

これは開発には問題ありませんが、私はステージングサーバー(カスタムconfig/environments/staging.rb設定ファイルを使用しています)にデプロイしたときに、メールを配信しようとしたときに「接続が拒否されました」というエラーが表示されます。 staging.rbにはメーラー関連の設定はまったくありません。

は、だから私は RAILS_ENV=staging rails cとステージングサーバーのコンソールを解雇し、「Rails.application.config.action_mailer置く」私は environment.rbに入れた設定が有効に実際にあることを示しているが、何らかの理由でactionmailerのは、それらを使用していません。

私は実験を通して、configを直接staging.rbにコピーすると問題が解決することが分かりました。なぜこれが必要ですか?レールコンソールに設定が有効であることが示されている場合、ActionMailerはその設定を使用していないのはなぜですか?私は本当にのStackOverflowのSQLを見てみたいと思います

MyMailer.foo(Person.find(1)).delivery_method 

=> #<Mail::SMTP:0x0000000370d4d0 @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}> 

答えて

12

MyApp::Application.initialize!

+3

MyApp::Application.configure do config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: "smtp.elasticemail.com", port: 2525, domain: "myapp.com", authentication: "plain", user_name: "my_username", password: "my_password", enable_starttls_auto: true } end 

を置く:

深く掘り、私は予想通り、私のメーラークラスのdelivery_methodが設定されていないことを確認します私の質問が投稿されたときのログと、あなたが答えた(そして解決した)ログは、30秒未満でなければならなかった。 –

+0

haha​​ha:Pそうだね:P –

+0

大きな質問!素晴らしい答え!私のために厄介な問題を解決しました。 – thisfeller

関連する問題