Simple Rails 3 mail interceptor to redirect action mailer messages to a test address.
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
Gemfile
README.markdown
Rakefile
mail-redirector.gemspec

README.markdown

Mail Redirector

Installation

In Your Gemfile

gem 'mail-redirector'

In config/initializers/mail-redirector.rb

MailRedirector.setup_interceptor 'test@example.com'

That's it!

What it's doing

In all environments other than PRODUCTION or TEST, mail sent through ActionMailer will be redirected to test@example.com. No mail will be sent to its original destination. Instead, the X-Originally-To mail header will be set, allowing you to determine who the mail would have gone to had it not been redirected.

Mail in the TEST environment is specifically NOT redirected on the assumption that it is more convenient to configure action mailer to test delivery mode and still allow the tests to have access to the original to field for testing purposes.

I want more control!

If you want to change what addresses mail is redirected to in each environment, then INSTEAD of calling setup_interceptor, place a line of code like this:

ActionMailer::Base.register_interceptor(MailRedirector.new("test@example.com"))

In each environment file, or wherever makes sense for you.

Happy redirecting!