Skip to content

Instantly share code, notes, and snippets.

@ckib16
Created February 1, 2015 18:49
Show Gist options
  • Save ckib16/6b30e2493157f4391d36 to your computer and use it in GitHub Desktop.
Save ckib16/6b30e2493157f4391d36 to your computer and use it in GitHub Desktop.
# This interceptor just makes sure that local mail
# only emails you.
# http://edgeguides.rubyonrails.org/action_mailer_basics.html#intercepting-emails
class DevelopmentMailInterceptor
def self.delivering_email(message)
message.to = 'youremail@website.com'
message.cc = nil
message.bcc = nil
end
end
# Locally, outgoing mail will be 'intercepted' by the
# above DevelopmentMailInterceptor before going out
if Rails.env.development?
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor)
@ckib16
Copy link
Author

ckib16 commented Feb 1, 2015

Chris - what is the purpose of the interceptor code above? Is it mainly to test the email canbe sent out? I'm guessing the flow is:

  • I send an email locally from my Rails app (not from my email client like gmail or Mail.app)
  • The interceptor gets triggered and doesn't actually send the email, but stops it from being sent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment