<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>config.scoping == :important =&gt; true</title>
    <link>http://hollandonrails.nl/articles/481-config-scoping-important-true</link>
    <description>Last week I realised that using the config scope in your Rails environment files can be quite important.

We had the situation that we needed a different SMTP configuration for different environments.

In the environment.rb I found the following lines:

&lt;code&gt;
Rails::Initializer.run do |config|
  ...
end

ActionMailer::Base.smtp_settings = {
  :address =&gt; &quot;127.0.0.1&quot;,
  :port    =&gt; 25,
  :domain  =&gt; &quot;hollandonrails.nl&quot;
}
&lt;/code&gt;

For the develoment environment I needed something else, so I proceeded to add the following to development.rb:

&lt;code&gt;
ActionMailer::Base.smtp_settings = {
  :address =&gt; &quot;mail.google.com&quot;,
  :port    =&gt; 25,
  :domain  =&gt; &quot;bla.com&quot;
}
&lt;/code&gt;

But then the emails were not sent in the dev environment. Not knowing the cause, I spent an hour or two figuring this out.

Finally, I found out that the ActionMailer settings given in development.rb were not used. Some more investigation revealed the following things:

* ActionMailer is not defined within the Rails::Initializer block in environment.rb
* Using ActionMailer inside development.rb does NOT raise an error, but the scope of development.rb seems to be the same Rails::Initializer block
* Setting ActionMailer settings using config.action_mailer (like below) does allow overriding of these settings

&lt;code&gt;
config.action_mailer.smtp_settings = {
  :address =&gt; &quot;127.0.0.1&quot;,
  :port    =&gt; 25,
  :domain  =&gt; &quot;hollandonrails.nl&quot;
}
&lt;/code&gt;</description>
  </channel>
</rss>
