Created
September 4, 2011 13:32
-
-
Save scottwater/1192857 to your computer and use it in GitHub Desktop.
Supporting Multiple SMTP Servers in Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Postmarker | |
def postmark_mail(*args) | |
mail_message = mail(*args) | |
if can_use_postmark?(mail_message.From.to_s) | |
mail_message.delivery_method.settings.merge!( | |
:address => 'smtp.postmarkapp.com', | |
:user_name => ENV['POSTMARK_API_KEY'], | |
:password => ENV['POSTMARK_API_KEY'], | |
:port => 2525, | |
:authentication => 'plain', | |
:enable_starttls_auto => true, | |
:domain => 'kickofflabs.com') | |
end | |
mail_message | |
end | |
def can_use_postmark?(from_address) | |
ENV['POSTMARK_API_KEY'] && Rails.env.production? && valid_address?(from_address) | |
end | |
def valid_address?(from_address) | |
%w{[email protected] [email protected]}.include?(from_address) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment