public
Last active

Set staging environment email to go to a single email address you control in order to not accidentally send production email addresses staging data.

  • Download Gist
single_recipient_smtp.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14
module SingleRecipientSmtp
def self.included(clazz)
clazz.class_eval do
cattr_accessor :single_recipient_smtp_settings
end
end
 
def perform_delivery_single_recipient_smtp(mail)
mail.to = single_recipient_smtp_settings[:to]
mail.cc = nil
mail.bcc = nil
perform_delivery_smtp mail
end
end
staging.rb
Ruby
1 2 3 4 5
config.action_mailer.delivery_method = :single_recipient_smtp
ActionMailer::Base.send :include, SingleRecipientSmtp
ActionMailer::Base.single_recipient_smtp_settings = {
:to => 'staging@example.com'
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.