title: ActionMailer not delivering mail when SMTP settings configured dynamically
body: <p>I'm trying to set up ActionMailer's SMTP settings to be able to be configured at run time, but when that happens it doesn't seem to connect to the 3rd party service to deliver the mail. Below are 2 scenarios, the first of which the mail will send and deliver, the second of which nothing happens. I'm using the development environment for testing</p>
  
  <p><strong>This configuration is common to both scenarios</strong></p>
  
  <pre><code># config/environments/development.rb
  
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = false
  config.action_mailer.default :charset =&gt; "utf-8"
  config.action_mailer.delivery_method = :smtp
  </code></pre>
  
  <p><strong>This works:</strong></p>
  
  <pre><code># config/environments/development.rb
  
  config.action_mailer.default_url_options = { host: 'www.mysite.com' }
  config.action_mailer.smtp_settings = {
    :address              =&gt; "smtp.thirdpartyservice.com",
    :port                 =&gt; 587,
    :domain               =&gt; 'mysite.com',
    :user_name            =&gt; "me@mysite.com",
    :password             =&gt; "my-password",
    :authentication       =&gt; "plain",
    :enable_starttls_auto =&gt; true
  }
  </code></pre>
  
  <p>This delivers the mail, but also when tailing the logs, there is a slight delay in the request so I know the request is being made to the third party service.</p>
  
  <p><strong>This doesn't work:</strong></p>
  
  <p>This is the setup I want, using a custom mailer that I'm using.</p>
  
  <pre><code>class MyCustomMailer &lt; Devise::Mailer
    before_filter :use_smtp_settings
  
    def example_mailer(record)
      Rails.logger.warn self.smtp_settings
      @resource = record
      mail(to: record.email,
       from: AppSettings.first.mailer_sender,
       subject: "Example")
    end
  
    private
  
    def use_smtp_settings
      self.default_url_options[:host] = AppSettings.first.domain_address
      self.smtp_settings = {
        :address              =&gt; AppSettings.first.smtp_address,
        :port                 =&gt; AppSettings.first.smtp_port,
        :domain               =&gt; AppSettings.first.smtp_domain,
        :user_name            =&gt; AppSettings.first.smtp_username,
        :password             =&gt; AppSettings.first.smtp_password,
        :authentication       =&gt; "plain",
        :enable_starttls_auto =&gt; true
      }
    end
  end
  </code></pre>
  
  <p>The rails logger in the <code>#example_mailer()</code> method shows the same attributes that are used in the first example, albeit loaded from the <code>app_settings</code> table. However when tailing the logs this time, there is no delay so ActionMailer doesn't seem to even try making a request to the third party service.</p>