Last Updated: February 25, 2016
·
1.286K
· estevaoam

How to intercept every email when developing using production data

If you have the habit to use production data to test your application locally you possibly have deactivated the mailer to avoid sending test emails for your users.

Here's a cool trick that intercepts any mail and sets the "to" param to your email address.

Create a file in config/initializers/ with this content:

if Rails.env.development?
  class DevelopmentInterceptor
    def self.delivering_email(message)
      message.to  = "\"#{message.to.first}\" <youremail@gmail.com>"
      message.cc, message.bcc = nil, nil
    end 
  end 

  ActionMailer::Base.register_interceptor(DevelopmentInterceptor)
end

Don't forget to replace with your email address and that's it, it'll send everything to your email address when in the development environment.

1 Response
Add your response

Very cool.

I've used Ryan's letteropener gem too, and it works great:
https://github.com/ryanb/letter
opener

over 1 year ago ·