What is the difference between config.action_mailer.smtp_settings and ActionMailer :: Base.smtp_settings in Rails?

I installed an Exchange-compatible mail server in a RoR application. I used the following setting in development.rb :

 config.action_mailer.smtp_settings = { :address => 'mail.server.com', :port => 5870, :user_name => 'username', :password => 'password', :authentication => :login } 

This setup does not work, I get Net::SMTPAuthenticationError: 504 Unrecognized authentication type.

However, if I apply the same configuration in environment.rb , it works fine:

 ActionMailer::Base.smtp_settings = { :address => 'mail.server.com', :port => 5870, :user_name => 'username', :password => 'password', :authentication => :login } 

Why is this? Shouldn't config.action_mailer.smtp_settings set the same settings? This is mistake? Does this have a reason?

I tried this with Gmail as it is here and it works , so smtp_settings has an effect on the mail program, but it seems to me that not all options are considered / work.

+8
ruby-on-rails actionmailer
source share
2 answers

config.action_mailer.smtp_settings transfers the settings to ActionMailer::Base.smtp_settings .

However, the main difference is that the first parameter is the environment, and the second is global.

In other words, you must set config.action_mailer.smtp_settings to the appropriate environment file in order to apply the settings. If you want to use the settings in production, for example, add the destination to the config/environments/production.rb file. Similarly, if you want the settings to be applied to the entire project, set them in config/application.rb .

+4
source share

I had a similar problem, config.action_mailer.smtp_settings did not work, but each configuration was correct.

Finally, I realized that the Rails extension overrides the settings of ActionMailer :: Base in the initialization phase ... Therefore, examine all your code and all third-party codes (!), Extensions, modules, etc. The problem must be!

+2
source share

All Articles