Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.