Skip to content

Instantly share code, notes, and snippets.

@scottwater
Created September 4, 2011 13:32
Show Gist options
  • Save scottwater/1192857 to your computer and use it in GitHub Desktop.
Save scottwater/1192857 to your computer and use it in GitHub Desktop.
Supporting Multiple SMTP Servers in Rails
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