This project is archived and is in readonly mode.

#2559 ✓resolved
laserlemon

Inheritable ActionMailer server settings

Reported by laserlemon | April 24th, 2009 @ 03:38 PM | in 3.0.2

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'
}

Comments and changes to this ticket

  • Will Bryant

    Will Bryant May 12th, 2009 @ 05:15 AM

    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.

  • Joe Noon

    Joe Noon July 22nd, 2009 @ 01:32 AM

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

  • José Valim

    José Valim August 8th, 2009 @ 12:34 PM

    • Tag changed from actionmailer, inheritance, patch, smtp to actionmailer, bugmash, inheritance, patch, smtp
  • Josh Nichols

    Josh Nichols August 9th, 2009 @ 10:23 PM

    +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.

  • Rizwan Reza

    Rizwan Reza January 20th, 2010 @ 11:29 AM

    • 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.

  • José Valim

    José Valim January 20th, 2010 @ 11:55 AM

    • 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.

  • José Valim

    José Valim January 26th, 2010 @ 08:11 PM

    • State changed from “open” to “resolved”

    Solved on master.

  • Jeremy Kemper

    Jeremy Kemper October 15th, 2010 @ 11:01 PM

    • Milestone set to 3.0.2
    • Importance changed from “” to “Medium”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages