Created
June 15, 2012 21:52
-
-
Save croaky/2938882 to your computer and use it in GitHub Desktop.
SingleRecipientSmtp
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
class SingleRecipientSmtp < ::Mail::SMTP | |
def initialize(_) | |
self.settings = { | |
address: 'smtp.sendgrid.net', | |
authentication: :plain, | |
domain: 'myapp.com', | |
password: ENV['SENDGRID_PASSWORD'], | |
port: '587', | |
user_name: ENV['SENDGRID_USERNAME'] | |
} | |
end | |
def deliver!(mail) | |
mail.to.each do |recipient| | |
log "*** suppressing mail to #{recipient}" | |
end | |
mail.to = 'staging@myapp.com' | |
mail.cc = nil | |
mail.bcc = nil | |
super mail | |
end | |
def log(message) | |
if defined? Rails | |
Rails.logger.warn message | |
end | |
end | |
end |
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
require Rails.root.join('lib', 'single_recipient_smtp') | |
MyApp::Application.configure do | |
# ... | |
config.action_mailer.delivery_method = SingleRecipientSmtp | |
# ... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment