Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

mailer guide: fixes indentation, and use fixed width fonts wherever n…

…ecessary
  • Loading branch information...
commit 155f734155fd0772d19f4201f244dccd8cdbd126 1 parent 0df00d9
Vijay Dev vijaydev authored fxn committed

Showing 1 changed file with 26 additions and 31 deletions. Show diff stats Hide diff stats

  1. +26 31 railties/guides/source/action_mailer_basics.textile
57 railties/guides/source/action_mailer_basics.textile
Source Rendered
@@ -8,7 +8,7 @@ WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not
8 8
9 9 h3. Introduction
10 10
11   -Action Mailer allows you to send emails from your application using a mailer model and views. So, in Rails, emails are used by creating mailers that inherit from +ActionMailer::Base+ and live in +app/mailers+. Those mailers have associated views that appear alongside controller views in +app/views+.
  11 +Action Mailer allows you to send emails from your application using a mailer model and views. So, in Rails, emails are used by creating mailers that inherit from +ActionMailer::Base+ and live in +app/mailers+. Those mailers have associated views that appear alongside controller views in +app/views+.
12 12
13 13 h3. Sending Emails
14 14
@@ -48,10 +48,8 @@ class UserMailer < ActionMailer::Base
48 48 def welcome_email(user)
49 49 @user = user
50 50 @url = "http://example.com/login"
51   - mail(:to => user.email,
52   - :subject => "Welcome to My Awesome Site")
  51 + mail(:to => user.email, :subject => "Welcome to My Awesome Site")
53 52 end
54   -
55 53 end
56 54 </ruby>
57 55
@@ -142,17 +140,17 @@ end
142 140
143 141 This provides a much simpler implementation that does not require the registering of observers and the like.
144 142
145   -The method +welcome_email+ returns a Mail::Message object which can then just be told +deliver+ to send itself out.
  143 +The method +welcome_email+ returns a <tt>Mail::Message</tt> object which can then just be told +deliver+ to send itself out.
146 144
147 145 NOTE: In previous versions of Rails, you would call +deliver_welcome_email+ or +create_welcome_email+. This has been deprecated in Rails 3.0 in favour of just calling the method name itself.
148 146
149   -WARNING: Sending out one email should only take a fraction of a second, if you are planning on sending out many emails, or you have a slow domain resolution service, you might want to investigate using a background process like delayed job.
  147 +WARNING: Sending out an email should only take a fraction of a second, but if you are planning on sending out many emails, or you have a slow domain resolution service, you might want to investigate using a background process like Delayed Job.
150 148
151 149 h4. Auto encoding header values
152 150
153 151 Action Mailer now handles the auto encoding of multibyte characters inside of headers and bodies.
154 152
155   -If you are using UTF-8 as your character set, you do not have to do anything special, just go ahead and send in UTF-8 data to the address fields, subject, keywords, filenames or body of the email and ActionMailer will auto encode it into quoted printable for you in the case of a header field or Base64 encode any body parts that are non US-ASCII.
  153 +If you are using UTF-8 as your character set, you do not have to do anything special, just go ahead and send in UTF-8 data to the address fields, subject, keywords, filenames or body of the email and Action Mailer will auto encode it into quoted printable for you in the case of a header field or Base64 encode any body parts that are non US-ASCII.
156 154
157 155 For more complex examples such as defining alternate character sets or self encoding text first, please refer to the Mail library.
158 156
@@ -213,7 +211,7 @@ NOTE: If you specify an encoding, Mail will assume that your content is already
213 211
214 212 h5. Making Inline Attachments
215 213
216   -ActionMailer 3.0 makes inline attachments, which involved a lot of hacking in pre 3.0 versions, much simpler and trivial as they should be.
  214 +Action Mailer 3.0 makes inline attachments, which involved a lot of hacking in pre 3.0 versions, much simpler and trivial as they should be.
217 215
218 216 * Firstly, to tell Mail to turn an attachment into an inline attachment, you just call <tt>#inline</tt> on the attachments method within your Mailer:
219 217
@@ -245,15 +243,15 @@ h5. Sending Email To Multiple Recipients
245 243 It is possible to send email to one or more recipients in one email (for e.g. informing all admins of a new signup) by setting the list of emails to the <tt>:to</tt> key. The list of emails can be an array of email addresses or a single string with the addresses separated by commas.
246 244
247 245 <ruby>
248   - class AdminMailer < ActionMailer::Base
249   - default :to => Admin.all.map(&:email),
250   - :from => "notification@example.com"
  246 +class AdminMailer < ActionMailer::Base
  247 + default :to => Admin.all.map(&:email),
  248 + :from => "notification@example.com"
251 249
252   - def new_registration(user)
253   - @user = user
254   - mail(:subject => "New User Signup: #{@user.email}")
255   - end
  250 + def new_registration(user)
  251 + @user = user
  252 + mail(:subject => "New User Signup: #{@user.email}")
256 253 end
  254 +end
257 255 </ruby>
258 256
259 257 The same format can be used to set carbon copy (Cc:) and blind carbon copy (Bcc:) recipients, by using the <tt>:cc</tt> and <tt>:bcc</tt> keys respectively.
@@ -264,12 +262,11 @@ Sometimes you wish to show the name of the person instead of just their email ad
264 262 to format the email address in the format <tt>"Name &lt;email&gt;"</tt>.
265 263
266 264 <ruby>
267   - def welcome_email(user)
268   - @user = user
269   - email_with_name = "#{@user.name} <#{@user.email}>"
270   - mail(:to => email_with_name,
271   - :subject => "Welcome to My Awesome Site")
272   - end
  265 +def welcome_email(user)
  266 + @user = user
  267 + email_with_name = "#{@user.name} <#{@user.email}>"
  268 + mail(:to => email_with_name, :subject => "Welcome to My Awesome Site")
  269 +end
273 270 </ruby>
274 271
275 272 h4. Mailer Views
@@ -289,9 +286,7 @@ class UserMailer < ActionMailer::Base
289 286 :subject => "Welcome to My Awesome Site",
290 287 :template_path => 'notifications',
291 288 :template_name => 'another')
292   - end
293 289 end
294   -
295 290 end
296 291 </ruby>
297 292
@@ -461,14 +456,14 @@ h3. Action Mailer Configuration
461 456
462 457 The following configuration options are best made in one of the environment files (environment.rb, production.rb, etc...)
463 458
464   -|template_root|Determines the base from which template references will be made.|
465   -|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.|
466   -|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></ul>|
467   -|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>|
468   -|raise_delivery_errors|Whether or not errors should be raised if the email fails to be delivered.|
469   -|delivery_method|Defines a delivery method. Possible values are :smtp (default), :sendmail, :file and :test.|
470   -|perform_deliveries|Determines whether deliveries are actually carried out when the +deliver+ method is invoked on the Mail message. By default they are, but this can be turned off to help functional testing.|
471   -|deliveries|Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test. Most useful for unit and functional testing.|
  459 +|+template_root+|Determines the base from which template references will be made.|
  460 +|+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.|
  461 +|+smtp_settings+|Allows detailed configuration for <tt>:smtp</tt> delivery method:<ul><li><tt>:address</tt> - Allows you to use a remote mail server. Just change it from its default "localhost" setting.</li><li><tt>:port</tt> - On the off chance that your mail server doesn't run on port 25, you can change it.</li><li><tt>:domain</tt> - If you need to specify a HELO domain, you can do it here.</li><li><tt>:user_name</tt> - If your mail server requires authentication, set the username in this setting.</li><li><tt>:password</tt> - If your mail server requires authentication, set the password in this setting.</li><li><tt>:authentication</tt> - If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of <tt>:plain</tt>, <tt>:login</tt>, <tt>:cram_md5</tt>.</li></ul>|
  462 +|+sendmail_settings+|Allows you to override options for the <tt>:sendmail</tt> delivery method.<ul><li><tt>:location</tt> - The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>.</li><li><tt>:arguments</tt> - The command line arguments to be passed to sendmail. Defaults to <tt>-i -t</tt>.</li></ul>|
  463 +|+raise_delivery_errors+|Whether or not errors should be raised if the email fails to be delivered.|
  464 +|+delivery_method+|Defines a delivery method. Possible values are <tt>:smtp</tt> (default), <tt>:sendmail</tt>, <tt>:file</tt> and <tt>:test</tt>.|
  465 +|+perform_deliveries+|Determines whether deliveries are actually carried out when the +deliver+ method is invoked on the Mail message. By default they are, but this can be turned off to help functional testing.|
  466 +|+deliveries+|Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test. Most useful for unit and functional testing.|
472 467
473 468 h4. Example Action Mailer Configuration
474 469

0 comments on commit 155f734

Please sign in to comment.
Something went wrong with that request. Please try again.