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.
Written by Estevão Mascarenhas
Related protips
1 Response
Very cool.
I've used Ryan's letteropener gem too, and it works great:
https://github.com/ryanb/letteropener
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#