Skip to content

Commit 3c60da7

Browse files
committed
Merge pull request rails#15618 from JuanitoFatas/doc/action-mailer-guide
[ci skip] Refine Action Mailer guide.
2 parents 98575c6 + 2e19038 commit 3c60da7

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

guides/source/action_mailer_basics.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ After reading this guide, you will know:
1717
Introduction
1818
------------
1919

20-
Action Mailer allows you to send emails from your application using mailer classes and views. Mailers work very similarly to controllers. They inherit from `ActionMailer::Base` and live in `app/mailers`, and they have associated views that appear in `app/views`.
20+
Action Mailer allows you to send emails from your application using mailer classes
21+
and views. Mailers work very similarly to controllers. They inherit from
22+
`ActionMailer::Base` and live in `app/mailers`, and they have associated views
23+
that appear in `app/views`.
2124

2225
Sending Emails
2326
--------------
@@ -84,8 +87,11 @@ Here is a quick explanation of the items presented in the preceding method. For
8487
a full list of all available options, please have a look further down at the
8588
Complete List of Action Mailer user-settable attributes section.
8689

87-
* `default Hash` - This is a hash of default values for any email you send from this mailer. In this case we are setting the `:from` header to a value for all messages in this class. This can be overridden on a per-email basis.
88-
* `mail` - The actual email message, we are passing the `:to` and `:subject` headers in.
90+
* `default Hash` - This is a hash of default values for any email you send from
91+
this mailer. In this case we are setting the `:from` header to a value for all
92+
messages in this class. This can be overridden on a per-email basis.
93+
* `mail` - The actual email message, we are passing the `:to` and `:subject`
94+
headers in.
8995

9096
Just like controllers, any instance variables we define in the method become
9197
available for use in the views.
@@ -151,7 +157,7 @@ $ bin/rake db:migrate
151157
```
152158

153159
Now that we have a user model to play with, we will just edit the
154-
`app/controllers/users_controller.rb` make it instruct the UserMailer to deliver
160+
`app/controllers/users_controller.rb` make it instruct the `UserMailer` to deliver
155161
an email to the newly created user by editing the create action and inserting a
156162
call to `UserMailer.welcome_email` right after the user is successfully saved:
157163

@@ -230,9 +236,11 @@ different, encode your content and pass in the encoded content and encoding in a
230236

231237
```ruby
232238
encoded_content = SpecialEncode(File.read('/path/to/filename.jpg'))
233-
attachments['filename.jpg'] = {mime_type: 'application/x-gzip',
234-
encoding: 'SpecialEncoding',
235-
content: encoded_content }
239+
attachments['filename.jpg'] = {
240+
mime_type: 'application/x-gzip',
241+
encoding: 'SpecialEncoding',
242+
content: encoded_content
243+
}
236244
```
237245

238246
NOTE: If you specify an encoding, Mail will assume that your content is already
@@ -608,7 +616,7 @@ files (environment.rb, production.rb, etc...)
608616
| Configuration | Description |
609617
|---------------|-------------|
610618
|`logger`|Generates information on the mailing run if available. Can be set to `nil` for no logging. Compatible with both Ruby's own `Logger` and `Log4r` loggers.|
611-
|`smtp_settings`|Allows detailed configuration for `:smtp` delivery method:<ul><li>`:address` - Allows you to use a remote mail server. Just change it from its default "localhost" setting.</li><li>`:port` - On the off chance that your mail server doesn't run on port 25, you can change it.</li><li>`:domain` - If you need to specify a HELO domain, you can do it here.</li><li>`:user_name` - If your mail server requires authentication, set the username in this setting.</li><li>`:password` - If your mail server requires authentication, set the password in this setting.</li><li>`:authentication` - If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of `:plain`, `:login`, `:cram_md5`.</li><li>`:enable_starttls_auto` - Set this to `false` if there is a problem with your server certificate that you cannot resolve.</li></ul>|
619+
|`smtp_settings`|Allows detailed configuration for `:smtp` delivery method:<ul><li>`:address` - Allows you to use a remote mail server. Just change it from its default `"localhost"` setting.</li><li>`:port` - On the off chance that your mail server doesn't run on port 25, you can change it.</li><li>`:domain` - If you need to specify a HELO domain, you can do it here.</li><li>`:user_name` - If your mail server requires authentication, set the username in this setting.</li><li>`:password` - If your mail server requires authentication, set the password in this setting.</li><li>`:authentication` - If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of `:plain`, `:login`, `:cram_md5`.</li><li>`:enable_starttls_auto` - Set this to `false` if there is a problem with your server certificate that you cannot resolve.</li></ul>|
612620
|`sendmail_settings`|Allows you to override options for the `:sendmail` delivery method.<ul><li>`:location` - The location of the sendmail executable. Defaults to `/usr/sbin/sendmail`.</li><li>`:arguments` - The command line arguments to be passed to sendmail. Defaults to `-i -t`.</li></ul>|
613621
|`raise_delivery_errors`|Whether or not errors should be raised if the email fails to be delivered. This only works if the external email server is configured for immediate delivery.|
614622
|`delivery_method`|Defines a delivery method. Possible values are:<ul><li>`:smtp` (default), can be configured by using `config.action_mailer.smtp_settings`.</li><li>`:sendmail`, can be configured by using `config.action_mailer.sendmail_settings`.</li><li>`:file`: save emails to files; can be configured by using `config.action_mailer.file_settings`.</li><li>`:test`: save emails to `ActionMailer::Base.deliveries` array.</li></ul>See [API docs](http://api.rubyonrails.org/classes/ActionMailer/Base.html) for more info.|
@@ -617,7 +625,7 @@ files (environment.rb, production.rb, etc...)
617625
|`default_options`|Allows you to set default values for the `mail` method options (`:from`, `:reply_to`, etc.).|
618626

619627
For a complete writeup of possible configurations see the
620-
[Action Mailer section](configuring.html#configuring-action-mailer) in
628+
[Configuring Action Mailer](configuring.html#configuring-action-mailer) in
621629
our Configuring Rails Applications guide.
622630

623631
### Example Action Mailer Configuration
@@ -662,6 +670,7 @@ You can find detailed instructions on how to test your mailers in the
662670

663671
Intercepting Emails
664672
-------------------
673+
665674
There are situations where you need to edit an email before it's
666675
delivered. Fortunately Action Mailer provides hooks to intercept every
667676
email. You can register an interceptor to make modifications to mail messages
@@ -685,5 +694,5 @@ ActionMailer::Base.register_interceptor(SandboxEmailInterceptor) if Rails.env.st
685694
686695
NOTE: The example above uses a custom environment called "staging" for a
687696
production like server but for testing purposes. You can read
688-
[Creating Rails environments](./configuring.html#creating-rails-environments)
697+
[Creating Rails environments](configuring.html#creating-rails-environments)
689698
for more information about custom Rails environments.

0 commit comments

Comments
 (0)