Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Inheritable ActionMailer server settings

#2559

When sending mail through Gmail servers, the "from" email address is changed to match the address used in the SMTP authentication. However, it's often required to send emails from multiple addresses in one Rails application.

This patch allows for multiple ActionMailer server settings per application. After assigning the following in config/environment.rb,

ActionMailer::Base.smtp_settings = {
  :address => 'smtp.gmail.com',
  :port => '587',
  :domain => 'localhost.localdomain',
  :authentication => :plain,
  :user_name => 'do.not.reply@example.com',
  :password => 'password'
}

you can assign additional SMTP settings per ActionMailer::Base subclass:

SampleMailer.smtp_settings = {
  :user_name => 'please.reply@sample.com',
  :password => 'password'
}

Reported by laserlemon · April 24th, 2009 @ 03:38 PM

State: resolved
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: Medium

Activity

  1. Will Bryant
    Will Bryant

    As per Koz's suggestion on the mailing list, superclass_delegating_accessor works better - no test changes needed with that.

    That in itself works fine.

    However, trying to use it in a real project (2.2, at least) reveals a nasty oddity; if you access a mailer class in any way in your environment configuration (ie. production.rb), which is where config.action_mailer.smtp_settings is set and so would be the logical place to set YourSpecialMailer.smtp_settings also, then the YourSpecialMailer class gets loaded before the actionmailer view_paths have been set. As a result, you start getting weird ActionView::MissingTemplate exceptions like this:

    
    Missing template your_special_mailer/template_that_actually_does_exist.erb in view path 
      [RAILS_ROOT]/vendor/rails/actionpack/lib/action_view/template.rb:97:in `find_full_path'
    

    Fixing this is easy; we just need to change

    
        class_inheritable_accessor :view_paths
    

    To:

    
        superclass_delegating_accessor :view_paths
    

    This seems to work ok and solves that problem. Sound alright?

    Patches attached.

    May 12th, 2009 @ 05:15 AM

  2. Joe Noon
    Joe Noon

    per_mailer_mailer_settings.diff is working well for me. +1 and nice fix.

    July 22nd, 2009 @ 01:32 AM

  3. José Valim
    José Valim
    • Tag changed from actionmailer, inheritance, patch, smtp to actionmailer, bugmash, inheritance, patch, smtp

    August 8th, 2009 @ 12:34 PM

  4. Josh Nichols
    Josh Nichols

    +1 on the functionality, but there are no tests to verify them.

    I attached a patch that has failing tests (but no implementation). I tried Will's patch which uses superclass_delegating_accessor , but the tests still fail.

    I used the originally proposed class_inheritable_accessor, and that does seem to work.

    August 9th, 2009 @ 10:23 PM

  5. Rizwan Reza
    Rizwan Reza
    • State changed from new to verified
    • Tag changed from actionmailer, bugmash, inheritance, patch, smtp to actionmailer, inheritance, patch, smtp
    • Milestone changed from 2.x to 2.3.6

    I've verified the first patch, which applies cleanly.

    January 20th, 2010 @ 11:29 AM

  6. José Valim
    José Valim
    • State changed from verified to open
    • Assigned user set to José Valim
    • Milestone cleared.

    We have ActionMailer refactoring going in a branch, so I'm tracking this ticket to add this behavior on it.

    January 20th, 2010 @ 11:55 AM

  7. José Valim
    José Valim
    • State changed from open to resolved

    Solved on master.

    January 26th, 2010 @ 08:11 PM

  8. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to Medium

    October 15th, 2010 @ 11:01 PM