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_settin
Solution for Rails 3.2:
class SomeMailer < ActionMailer::Base
include AbstractController::Callbacks
after_filter :set_delivery_options
private
def set_delivery_options
settings = {
:address => 'smtp.server',
:port => 587,
:domain => 'your_domain',
:user_name => 'smtp_username',
:password => 'smtp_password',
:authentication => 'PLAIN' # or something
}
message.delivery_method.settings.merge!(settings)
end
end
Solution inspired by How to send emails with multiple, dynamic smtp using Actionmailer/Ruby on Rails