aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2013-01-16 15:04:37 -0800
committerXavier Noria <fxn@hashref.com>2013-01-16 15:04:37 -0800
commit1a989d473513fd891b1a39f414f9c300a8f7ea63 (patch)
treecc8fac918531c01b7d2a1397fbc2649c573fd4cb
parent89b0f4230f5302c2add13d0a1f2e99d66105b39e (diff)
parenta7772405dc900f0660404381faa5007b5f0f0d23 (diff)
downloadrails-1a989d473513fd891b1a39f414f9c300a8f7ea63.tar.gz
rails-1a989d473513fd891b1a39f414f9c300a8f7ea63.tar.bz2
rails-1a989d473513fd891b1a39f414f9c300a8f7ea63.zip
Merge pull request #8967 from senny/add_interceptor_to_am_doc
document Intercepters in ActionMailer guide
-rw-r--r--guides/source/action_mailer_basics.md20
1 files changed, 20 insertions, 0 deletions
diff --git a/guides/source/action_mailer_basics.md b/guides/source/action_mailer_basics.md
index 7c6ef52f4a..7f992025e4 100644
--- a/guides/source/action_mailer_basics.md
+++ b/guides/source/action_mailer_basics.md
@@ -575,3 +575,23 @@ end
```
In the test we send the email and store the returned object in the `email` variable. We then ensure that it was sent (the first assert), then, in the second batch of assertions, we ensure that the email does indeed contain what we expect.
+
+Intercepting Emails
+-------------------
+There are situations where you need to edit an email before it's delivered. Fortunately Action Mailer provides hooks to intercept every email. You can register an interceptor to make modifications to mail messages right before they are handed to the delivery agents.
+
+```ruby
+class SandboxEmailInterceptor
+ def self.delivering_email(message)
+ message.to = ['sandbox@example.com']
+ end
+end
+```
+
+Before the Interceptor can do it's job you need to register it with the Action Mailer framework. You can do this in an initializer file `config/initializers/sandbox_email_interceptor.rb`
+
+```ruby
+ActionMailer::Base.register_interceptor(SandboxEmailInterceptor) if Rails.env.staging?
+```
+
+NOTE: The example above uses a custom environment called "staging" for a production like server but for testing purposes.