Skip to content

Instantly share code, notes, and snippets.

@ruckus
Created September 9, 2016 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruckus/1f60614668f64f9c923ecffa52dd1443 to your computer and use it in GitHub Desktop.
Save ruckus/1f60614668f64f9c923ecffa52dd1443 to your computer and use it in GitHub Desktop.
Place in `config/initializers/mailer_recipient_override.rb` and be sure to define an environment variable for `EMAIL_RECIPIENT_OVERRIDE`
class OverrideMailReciptient
def self.delivering_email(mail)
if Rails.env.development?
original_to = mail.to
mail.to = ENV['EMAIL_RECIPIENT_OVERRIDE']
mail.subject = "[DEVELOPMENT] #{mail.subject} - Recipient: #{original_to}"
if mail.cc && mail.cc.any?
new_body = "#{mail.body}\n\nRemoved CC: recipients: #{mail.cc.join(", ")}"
mail.body = new_body
mail.cc = []
end
end
if Rails.env.staging?
mail.subject = "[STAGING] #{mail.subject}"
# clear all CC list
mail.cc = []
end
end
end
ActionMailer::Base.register_interceptor(OverrideMailReciptient)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment