Created
September 9, 2016 21:40
-
-
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`
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 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