Created
January 6, 2011 18:32
-
-
Save laurynas/768310 to your computer and use it in GitHub Desktop.
Add option to deliver all ActionMailer mails to one address. Useful in staging environment.
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
# Initializer: | |
# require 'mail_delivery_catchall.rb' if Rails.env.staging? | |
# Rails 3 | |
module ActionMailer | |
class Base | |
class << self | |
def deliver_mail_with_catchall(mail, &block) | |
original_to = mail.to | |
mail.to = APP_CONFIG[:email][:tests_to] | |
mail.cc = "" | |
mail.bcc = "" | |
mail.subject = "#{mail.subject} / Original To: #{original_to}" | |
Rails.logger.info "Mail delivery catchall: #{original_to} => #{mail.to}" | |
deliver_mail_without_catchall(mail, &block) | |
end | |
alias_method_chain :deliver_mail, :catchall | |
end | |
end | |
end | |
# ---------------------------------------------------------------------------- | |
# Rails 2 | |
# Add option to deliver all mails to one address. Useful in staging environment. | |
# config.action_mailer.delivery_method = :catchall | |
module ActionMailer | |
class Base | |
def perform_delivery_catchall(mail) | |
original_to = mail.to | |
mail.to = Setting.catchall_email | |
mail.cc = "" | |
mail.bcc = "" | |
mail.subject = "#{mail.subject} / Original To: #{original_to}" | |
Rails.logger.info "Mail delivery catchall: #{original_to} => #{mail.to}" | |
perform_delivery_sendmail(mail) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment