Skip to content

Instantly share code, notes, and snippets.

@pbyrne
Last active December 11, 2015 21:48
Show Gist options
  • Save pbyrne/4665235 to your computer and use it in GitHub Desktop.
Save pbyrne/4665235 to your computer and use it in GitHub Desktop.
Sample interceptor to interrupt outbound emails in non-production environments.
# put this in lib or a gem or something
class NonProductionInterceptor
def self.delivering_email(message)
# implement some mechanism to strip non-example.com and non-tstmedia.com email
# addresses from the delivery lists. also verify that if no delivery emails are
# left, either drop the email (if possible) or add nobody@example.com or some
# other dummy address so no exception is raised when attempting to deliver.
#
# Feel free to crib from TstMailer, of course.
#
# Also, this example seems to be a good fit: http://renderedtext.com/blog/2012/04/27/filtering-emails-on-staging/
end
end
# put this in an initializer
Mail.register_interceptor(NonProductionInterceptor) unless Rails.env.production?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment