I have a need to use two different smtp servers in a Rails application. It appears that the way ActionMailer is constructed, it is not possible to have different smtp_settings for a subclass. I could reload the smtp settings for each mailer class whenever a message is being sent, but that messes up the ExceptionNotifier plugin which is outside my control (unless I mess with it too). Does anyone have a solution/plugin for something like this?
Ideally I would like to have
class UserMailer < ActionMailer::Base; end
and then set in environment.rb
ActionMailer::Base.smtp_settings = standard_smtp_settings
UserMailer.smtp_settings = user_smtp_settings
Thus, most of my mailers including ExceptionNotifier would pickup the default settings, but the UserMailer would use a paid relay service.
Rails-2.3.*
Based on the Oreilly article, I came up with the solution I wrote about here: http://transfs.com/devblog/2009/12/03/custom-smtp-settings-for-a-specific-actionmailer-subclass
Here's the relevant code:
Here's another solution, which, while it looks ridiculous, I think is a little bit cleaner and easier to reuse in different AM::Base classes:
example Mailer:
Rails 4 allows for dynamic delivery options. The above code is straight from the action mailer basics guide, which you can find here: http://guides.rubyonrails.org/v4.0/action_mailer_basics.html#sending-emails-with-dynamic-delivery-options
With this, it is possible to have different smtp settings for every email you send, or, like in your use case for different sub classes like UserMailer, OtherMailer etc.
Solution for Rails 3.2:
Solution inspired by How to send emails with multiple, dynamic smtp using Actionmailer/Ruby on Rails
Tried to use jkrall's option with Rails 3.2.1 but for some reason it wouldn't override default configuration, but doing:
Similar to http://www.scottw.com/multiple-smtp-servers-with-action-mailer, made it work.