ActionMailer Interceptor

suggest change

Action Mailer provides interceptor hooks. These let you register classes that are called during the mail delivery life cycle.

An interceptor class must implement delivering_email(message). Action Mailer calls it before the email is sent, so you can change the email before it reaches the delivery agents. Modify the passed-in Mail::Message directly.

This is useful when developers should receive mail themselves instead of real users.

Register an Action Mailer interceptor like this:

# config/initializers/override_mail_recipient.rb

if Rails.env.development? or Rails.env.test?
  class OverrideMailRecipient
    def self.delivering_email(mail)
      mail.subject = 'This is dummy subject'
      mail.bcc = 'test_bcc@noemail.com'
      mail.to = 'test@noemail.com'
    end
  end
  ActionMailer::Base.register_interceptor(OverrideMailRecipient)
end

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents