Skip to content

Instantly share code, notes, and snippets.

@croaky
Created June 15, 2012 21:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save croaky/2938882 to your computer and use it in GitHub Desktop.
Save croaky/2938882 to your computer and use it in GitHub Desktop.
SingleRecipientSmtp
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
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