Skip to content

Commit cb2ed01

Browse files
authored
Merge pull request rails#42174 from rails/fix-action-mailer-basics-guide
2 parents e2e2ed4 + acbecc4 commit cb2ed01

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

guides/source/action_mailer_basics.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -877,13 +877,14 @@ class SandboxEmailInterceptor
877877
end
878878
```
879879

880-
Before the interceptor can do its job you need to register it using
881-
[`register_interceptor`][]. You can do this in an initializer file like
882-
`config/initializers/sandbox_email_interceptor.rb`:
880+
Before the interceptor can do its job you need to register it using the `interceptors` config option.
881+
You can do this in an initializer file like `config/initializers/mail_interceptors.rb`:
883882

884883
```ruby
885-
if Rails.env.staging?
886-
ActionMailer::Base.register_interceptor(SandboxEmailInterceptor)
884+
Rails.application.configure do
885+
if Rails.env.staging?
886+
config.action_mailer.interceptors = %w[SandboxEmailInterceptor]
887+
end
887888
end
888889
```
889890

@@ -892,8 +893,6 @@ production like server but for testing purposes. You can read
892893
[Creating Rails Environments](configuring.html#creating-rails-environments)
893894
for more information about custom Rails environments.
894895

895-
[`register_interceptor`]: https://api.rubyonrails.org/classes/ActionMailer/Base.html#method-c-register_interceptor
896-
897896
### Observing Emails
898897

899898
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
906905
end
907906
```
908907

909-
Similar to interceptors, you must register observers using [`register_observer`][]. You can do this in an initializer file
910-
like `config/initializers/email_delivery_observer.rb`:
908+
Similar to interceptors, you must register observers using the `observers` config option.
909+
You can do this in an initializer file like `config/initializers/mail_observers.rb`:
911910

912911
```ruby
913-
ActionMailer::Base.register_observer(EmailDeliveryObserver)
912+
Rails.application.configure do
913+
config.action_mailer.observers = %w[EmailDeliveryObserver]
914+
end
914915
```
915-
916-
[`register_observer`]: https://api.rubyonrails.org/classes/ActionMailer/Base.html#method-c-register_observer

0 commit comments

Comments
 (0)