Search code examples
ruby-on-railsemailtestingenvironmentactionmailer

Redirect all outgoing emails to single address for testing


In Ruby on Rails, I'm in a situation where I'd like my application (in a particular testing environment) to intercept all outgoing emails generated by the application and instead send them to a different, testing address (maybe also modifying the body to say "Initially sent to: ...").

I see ActionMailer has some hooks to observe or intercept mail, but I don't want to spin my own solution if there's an easier way to do this. Suggestions?


Solution

  • We're using the sanitize_email gem with much success. It sends all email to an address you specify and prepends the subject with the original recipient. It sounds like it does exactly what you want and has made QA-ing emails a breeze for us.