Skip to content

Instantly share code, notes, and snippets.

@apeckham
Created December 19, 2012 08:28
Show Gist options
  • Select an option

  • Save apeckham/4335288 to your computer and use it in GitHub Desktop.

Select an option

Save apeckham/4335288 to your computer and use it in GitHub Desktop.
Support multiple SMTP servers in ActionMailer subclasses in Rails 2.3 by setting the delivery method in a message header
module ActionMailer
class Base
def perform_delivery_from_header(tmail)
method = tmail.header.delete("x-delivery-method") || :server_2
send "perform_delivery_#{method}", tmail
end
def perform_delivery_server_1(tmail)
self.class.smtp_settings = {
address: "server1.smtp.com",
port: 25
}
perform_delivery_smtp tmail
end
def perform_delivery_server_2(tmail)
self.class.smtp_settings = {
address: "server2.smtp.com",
port: 587
}
perform_delivery_smtp tmail
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment