Juanda

Using MailSpyInterceptor to BCC yourself

When you’re running an early stage startup, it’s helpful to BCC yourself in every transactional email that your application sends. It might not be suited for big companies with tons of automated emails but it’s handy in this particular case. It will certainly help you to catch bugs and notice problems early on.

I created the MailSpyInterceptor gem. Once installed, it will simply BCC the email(s) that you define in every email that your system sends.

To use it, you need to add the gem to your Gemfile

# Gemfile
gem 'mail_spy_interceptor'

and register the interceptor in your environment file:

# config/environments/production.rb
Mail.register_interceptor(
  MailSpyInterceptor.new(ENV['EMAIL_RECIPIENTS'])
)

That’s it. You can pass a string with a single email or a string with comma separated emails.

If you want to know more about Mailer Interceptors, I recommend you to check the rails mailer guides