Merge pull request #42174 from rails/fix-action-mailer-basics-guide
This commit is contained in:
commit
cb2ed015a7
|
@ -877,13 +877,14 @@ class SandboxEmailInterceptor
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
Before the interceptor can do its job you need to register it using
|
Before the interceptor can do its job you need to register it using the `interceptors` config option.
|
||||||
[`register_interceptor`][]. You can do this in an initializer file like
|
You can do this in an initializer file like `config/initializers/mail_interceptors.rb`:
|
||||||
`config/initializers/sandbox_email_interceptor.rb`:
|
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
if Rails.env.staging?
|
Rails.application.configure do
|
||||||
ActionMailer::Base.register_interceptor(SandboxEmailInterceptor)
|
if Rails.env.staging?
|
||||||
|
config.action_mailer.interceptors = %w[SandboxEmailInterceptor]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -892,8 +893,6 @@ production like server but for testing purposes. You can read
|
||||||
[Creating Rails Environments](configuring.html#creating-rails-environments)
|
[Creating Rails Environments](configuring.html#creating-rails-environments)
|
||||||
for more information about custom Rails environments.
|
for more information about custom Rails environments.
|
||||||
|
|
||||||
[`register_interceptor`]: https://api.rubyonrails.org/classes/ActionMailer/Base.html#method-c-register_interceptor
|
|
||||||
|
|
||||||
### Observing Emails
|
### Observing Emails
|
||||||
|
|
||||||
Observers give you access to the email message after it has been sent. An observer class must implement the `:delivered_email(message)` method, which will be called after the email is sent.
|
Observers give you access to the email message after it has been sent. An observer class must implement the `:delivered_email(message)` method, which will be called after the email is sent.
|
||||||
|
@ -906,11 +905,11 @@ class EmailDeliveryObserver
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
Similar to interceptors, you must register observers using [`register_observer`][]. You can do this in an initializer file
|
Similar to interceptors, you must register observers using the `observers` config option.
|
||||||
like `config/initializers/email_delivery_observer.rb`:
|
You can do this in an initializer file like `config/initializers/mail_observers.rb`:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
ActionMailer::Base.register_observer(EmailDeliveryObserver)
|
Rails.application.configure do
|
||||||
|
config.action_mailer.observers = %w[EmailDeliveryObserver]
|
||||||
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
[`register_observer`]: https://api.rubyonrails.org/classes/ActionMailer/Base.html#method-c-register_observer
|
|
||||||
|
|
Loading…
Reference in New Issue