aboutsummaryrefslogtreecommitdiffstats
path: root/railties/doc/guides/html/action_mailer_basics.html
diff options
context:
space:
mode:
Diffstat (limited to 'railties/doc/guides/html/action_mailer_basics.html')
-rw-r--r--railties/doc/guides/html/action_mailer_basics.html358
1 files changed, 341 insertions, 17 deletions
diff --git a/railties/doc/guides/html/action_mailer_basics.html b/railties/doc/guides/html/action_mailer_basics.html
index 317f135e4c..c788591f72 100644
--- a/railties/doc/guides/html/action_mailer_basics.html
+++ b/railties/doc/guides/html/action_mailer_basics.html
@@ -31,19 +31,41 @@
<h2>Chapters</h2>
<ol>
<li>
- <a href="#_what_is_action_mailer">What is Action Mailer?</a>
+ <a href="#_introduction">Introduction</a>
</li>
<li>
- <a href="#_quick_walkthrough_to_creating_a_mailer">Quick walkthrough to creating a Mailer</a>
+ <a href="#_sending_emails">Sending Emails</a>
<ul>
- <li><a href="#_1_create_the_mailer">1. Create the mailer:</a></li>
+ <li><a href="#_walkthrough_to_generating_a_mailer">Walkthrough to generating a Mailer</a></li>
- <li><a href="#_2_edit_the_model">2. Edit the model:</a></li>
+ <li><a href="#_action_mailer_and_dynamic_deliver_methods">Action Mailer and dynamic deliver_ methods</a></li>
- <li><a href="#_3_create_the_mailer_view">3. Create the mailer view</a></li>
+ <li><a href="#_complete_list_of_actionmailer_user_settable_attributes">Complete List of ActionMailer user-settable attributes</a></li>
- <li><a href="#_4_wire_it_up_so_that_the_system_sends_the_email_when_a_user_signs_up">4. Wire it up so that the system sends the email when a user signs up</a></li>
+ <li><a href="#_mailer_views">Mailer Views</a></li>
+
+ <li><a href="#_action_mailer_layouts">Action Mailer Layouts</a></li>
+
+ <li><a href="#_sending_multipart_emails">Sending multipart emails</a></li>
+
+ </ul>
+ </li>
+ <li>
+ <a href="#_receiving_emails">Receiving Emails</a>
+ </li>
+ <li>
+ <a href="#_using_action_mailer_helpers">Using Action Mailer Helpers</a>
+ </li>
+ <li>
+ <a href="#_action_mailer_configuration">Action Mailer Configuration</a>
+ <ul>
+
+ <li><a href="#_example_action_mailer_configuration">Example Action Mailer Configuration</a></li>
+
+ <li><a href="#_action_mailer_configuration_for_gmail">Action Mailer Configuration for GMail</a></li>
+
+ <li><a href="#_configure_action_mailer_to_recognize_haml_templates">Configure Action Mailer to recognize HAML templates</a></li>
</ul>
</li>
@@ -66,15 +88,16 @@
<div class="paragraph"><p>This guide should provide you with all you need to get started in sending emails from your application, and will also cover how to test your mailers.</p></div>
</div>
</div>
-<h2 id="_what_is_action_mailer">1. What is Action Mailer?</h2>
+<h2 id="_introduction">1. Introduction</h2>
<div class="sectionbody">
<div class="paragraph"><p>Action Mailer allows you to send email from your application using a mailer model and views.
Yes, that is correct, in Rails, emails are used by creating Models that inherit from ActionMailer::Base. They live alongside other models in /app/models BUT they have views just like controllers that appear alongside other views in app/views.</p></div>
</div>
-<h2 id="_quick_walkthrough_to_creating_a_mailer">2. Quick walkthrough to creating a Mailer</h2>
+<h2 id="_sending_emails">2. Sending Emails</h2>
<div class="sectionbody">
<div class="paragraph"><p>Let&#8217;s say you want to send a welcome email to a user after they signup. Here is how you would go about this:</p></div>
-<h3 id="_1_create_the_mailer">2.1. 1. Create the mailer:</h3>
+<h3 id="_walkthrough_to_generating_a_mailer">2.1. Walkthrough to generating a Mailer</h3>
+<h4 id="_1_create_the_mailer">2.1.1. 1. Create the mailer:</h4>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
@@ -88,7 +111,7 @@ create test/fixtures/user_mailer
create app/models/user_mailer<span style="color: #990000">.</span>rb
create test/unit/user_mailer_test<span style="color: #990000">.</span>rb</tt></pre></div></div>
<div class="paragraph"><p>So we got the model, the fixtures, and the tests all created for us</p></div>
-<h3 id="_2_edit_the_model">2.2. 2. Edit the model:</h3>
+<h4 id="_2_edit_the_model">2.1.2. 2. Edit the model:</h4>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
@@ -122,7 +145,7 @@ subject: The subject of the email
sent_on: Timestamp for the email
content_type: The content type, by default is text/plain</p></div>
<div class="paragraph"><p>How about @body[:user]? Well anything you put in the @body hash will appear in the mailer view (more about mailer views below) as an instance variable ready for you to use, ie, in our example the mailer view will have a @user instance variable available for its consumption.</p></div>
-<h3 id="_3_create_the_mailer_view">2.3. 3. Create the mailer view</h3>
+<h4 id="_3_create_the_mailer_view">2.1.3. 3. Create the mailer view</h4>
<div class="paragraph"><p></p></div>
<div class="paragraph"><p>The file can look like:</p></div>
<div class="listingblock">
@@ -145,7 +168,7 @@ http://www.gnu.org/software/src-highlite -->
<span style="font-weight: bold"><span style="color: #0000FF">&lt;p&gt;</span></span>Thanks for joining and have a great day!<span style="font-weight: bold"><span style="color: #0000FF">&lt;/p&gt;</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">&lt;/body&gt;</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">&lt;/html&gt;</span></span></tt></pre></div></div>
-<h3 id="_4_wire_it_up_so_that_the_system_sends_the_email_when_a_user_signs_up">2.4. 4. Wire it up so that the system sends the email when a user signs up</h3>
+<h4 id="_4_wire_it_up_so_that_the_system_sends_the_email_when_a_user_signs_up">2.1.4. 4. Wire it up so that the system sends the email when a user signs up</h4>
<div class="paragraph"><p>There are 3 was to achieve this. One is to send the email from the controller that sends the email, another is to put it in a before_create block in the user model, and the last one is to use an observer on the user model. Whether you use the second or third methods is up to you, but staying away from the first is recommended. Not because it&#8217;s wrong, but because it keeps your controller clean, and keeps all logic related to the user model within the user model. This way, whichever way a user is created (from a web form, or from an API call, for example), we are guaranteed that the email will be sent.</p></div>
<div class="paragraph"><p></p></div>
<div class="listingblock">
@@ -190,10 +213,311 @@ http://www.gnu.org/software/src-highlite -->
UserMailer<span style="color: #990000">.</span>deliver_welcome_email<span style="color: #990000">(</span>user<span style="color: #990000">)</span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
-<div class="paragraph"><p>Notice how we call deliver_welcome_email? Where is that method? Well if you remember, we created a method called welcome_email in UserMailer, right? Well, as part of the "magic" of rails, we deliver the email identified by welcome_email by calling deliver_welcome_email.</p></div>
-<div class="paragraph"><p>That&#8217;s it! Now whenever your users signup, they will be greeted with a nice welcome email. Next up, we&#8217;ll talk about how to test a mailer model.</p></div>
+<div class="paragraph"><p>Notice how we call deliver_welcome_email? Where is that method? Well if you remember, we created a method called welcome_email in UserMailer, right? Well, as part of the "magic" of rails, we deliver the email identified by welcome_email by calling deliver_welcome_email. The next section will go through this in more detail.</p></div>
+<div class="paragraph"><p>That&#8217;s it! Now whenever your users signup, they will be greeted with a nice welcome email.</p></div>
+<h3 id="_action_mailer_and_dynamic_deliver_methods">2.2. Action Mailer and dynamic deliver_ methods</h3>
+<div class="paragraph"><p>So how does Action Mailer understand this deliver_welcome_email call? If you read the documentation (<a href="http://api.rubyonrails.org/files/vendor/rails/actionmailer/README.html">http://api.rubyonrails.org/files/vendor/rails/actionmailer/README.html</a>), you will find this in the "Sending Emails" section:</p></div>
+<div class="paragraph"><p>You never instantiate your mailer class. Rather, your delivery instance
+methods are automatically wrapped in class methods that start with the word
+deliver_ followed by the name of the mailer method that you would
+like to deliver. The signup_notification method defined above is
+delivered by invoking Notifier.deliver_signup_notification.</p></div>
+<div class="paragraph"><p>So, how exactly does this work?</p></div>
+<div class="paragraph"><p>In ActionMailer:Base, you will find this:</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 2.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">def</span></span> method_missing<span style="color: #990000">(</span>method_symbol<span style="color: #990000">,</span> <span style="color: #990000">*</span>parameters<span style="color: #990000">)</span><span style="font-style: italic"><span style="color: #9A1900">#:nodoc:</span></span>
+ <span style="font-weight: bold"><span style="color: #0000FF">case</span></span> method_symbol<span style="color: #990000">.</span>id2name
+ <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #FF6600">/^create_([_a-z]\w*)/</span> <span style="font-weight: bold"><span style="color: #0000FF">then</span></span> new<span style="color: #990000">(</span><span style="color: #009900">$1</span><span style="color: #990000">,</span> <span style="color: #990000">*</span>parameters<span style="color: #990000">).</span>mail
+ <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #FF6600">/^deliver_([_a-z]\w*)/</span> <span style="font-weight: bold"><span style="color: #0000FF">then</span></span> new<span style="color: #990000">(</span><span style="color: #009900">$1</span><span style="color: #990000">,</span> <span style="color: #990000">*</span>parameters<span style="color: #990000">).</span>deliver!
+ <span style="font-weight: bold"><span style="color: #0000FF">when</span></span> <span style="color: #FF0000">"new"</span> <span style="font-weight: bold"><span style="color: #0000FF">then</span></span> <span style="font-weight: bold"><span style="color: #0000FF">nil</span></span>
+ <span style="font-weight: bold"><span style="color: #0000FF">else</span></span> <span style="font-weight: bold"><span style="color: #0000FF">super</span></span>
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
+<div class="paragraph"><p>Ah, this makes things so much clearer :) so if the method name starts with deliver_ followed by any combination of lowercase letters or underscore, method missing calls new on your mailer class UserMailer in our example above, sending the combination of lower case letters or underscore, along with the parameter. The resulting object is then sent the deliver! method, which well... delivers it.</p></div>
+<h3 id="_complete_list_of_actionmailer_user_settable_attributes">2.3. Complete List of ActionMailer user-settable attributes</h3>
+<div class="tableblock">
+<table rules="all"
+width="100%"
+frame="border"
+cellspacing="0" cellpadding="4">
+<col width="20%" />
+<col width="80%" />
+<tbody valign="top">
+<tr>
+<td align="left"><p class="table">bcc</p></td>
+<td align="left"><p class="table">Specify the BCC addresses for the message</p></td>
+</tr>
+<tr>
+<td align="left"><p class="table">body</p></td>
+<td align="left"><p class="table">Define the body of the message. This is either a Hash (in which case it specifies the variables to pass to the template when it is rendered), or a string, in which case it specifies the actual text of the message.</p></td>
+</tr>
+<tr>
+<td align="left"><p class="table">cc</p></td>
+<td align="left"><p class="table">Specify the CC addresses for the message.</p></td>
+</tr>
+<tr>
+<td align="left"><p class="table">charset</p></td>
+<td align="left"><p class="table">Specify the charset to use for the message. This defaults to the default_charset specified for ActionMailer::Base.</p></td>
+</tr>
+<tr>
+<td align="left"><p class="table">content_type</p></td>
+<td align="left"><p class="table">Specify the content type for the message. This defaults to &lt;text/plain in most cases, but can be automatically set in some situations.</p></td>
+</tr>
+<tr>
+<td align="left"><p class="table">from</p></td>
+<td align="left"><p class="table">Specify the from address for the message.</p></td>
+</tr>
+<tr>
+<td align="left"><p class="table">reply_to</p></td>
+<td align="left"><p class="table">Specify the address (if different than the "from" address) to direct replies to this message.</p></td>
+</tr>
+<tr>
+<td align="left"><p class="table">headers</p></td>
+<td align="left"><p class="table">Specify additional headers to be added to the message.</p></td>
+</tr>
+<tr>
+<td align="left"><p class="table">implicit_parts_order</p></td>
+<td align="left"><p class="table">Specify the order in which parts should be sorted, based on content-type. This defaults to the value for the default_implicit_parts_order.</p></td>
+</tr>
+<tr>
+<td align="left"><p class="table">mime_version</p></td>
+<td align="left"><p class="table">Defaults to "1.0", but may be explicitly given if needed.</p></td>
+</tr>
+<tr>
+<td align="left"><p class="table">recipient</p></td>
+<td align="left"><p class="table">The recipient addresses for the message, either as a string (for a single address) or an array (for multiple addresses).</p></td>
+</tr>
+<tr>
+<td align="left"><p class="table">sent_on</p></td>
+<td align="left"><p class="table">The date on which the message was sent. If not set (the default), the header will be set by the delivery agent.</p></td>
+</tr>
+<tr>
+<td align="left"><p class="table">subject</p></td>
+<td align="left"><p class="table">Specify the subject of the message.</p></td>
+</tr>
+<tr>
+<td align="left"><p class="table">template</p></td>
+<td align="left"><p class="table">Specify the template name to use for current message. This is the "base" template name, without the extension or directory, and may be used to have multiple mailer methods share the same template.</p></td>
+</tr>
+</tbody>
+</table>
+</div>
+<h3 id="_mailer_views">2.4. Mailer Views</h3>
+<div class="paragraph"><p>Mailer views are located in /app/views/name_of_mailer_class. The specific mailer view is known to the class because it&#8217;s name is the same as the mailer method. So for example, in our example from above, our mailer view for the welcome_email method will be in /app/views/user_mailer/welcome_email.html.erb for the html version and welcome_email.txt.erb for the plain text version.</p></div>
+<div class="paragraph"><p>To change the default mailer view for your action you do something like:</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 2.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> UserMailer <span style="color: #990000">&lt;</span> ActionMailer<span style="color: #990000">::</span>Base
+
+ <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> welcome_email<span style="color: #990000">(</span>user<span style="color: #990000">)</span>
+ recipients user<span style="color: #990000">.</span>email
+ from <span style="color: #FF0000">"My Awesome Site Notifications&lt;notifications@example.com&gt;"</span>
+ subject <span style="color: #FF0000">"Welcome to My Awesome Site"</span>
+ sent_on Time<span style="color: #990000">.</span>now
+ body <span style="color: #FF0000">{</span><span style="color: #990000">:</span>user <span style="color: #990000">=&gt;</span> user<span style="color: #990000">,</span> <span style="color: #990000">:</span>url <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"http://example.com/login"</span><span style="color: #FF0000">}</span>
+ content_type <span style="color: #FF0000">"text/html"</span>
+
+ <span style="font-style: italic"><span style="color: #9A1900"># change the default from welcome_email.[html, txt].erb</span></span>
+ template <span style="color: #FF0000">"some_other_template"</span> <span style="font-style: italic"><span style="color: #9A1900"># this will be in app/views/user_mailer/some_other_template.[html, txt].erb</span></span>
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
+
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
+<h3 id="_action_mailer_layouts">2.5. Action Mailer Layouts</h3>
+<div class="paragraph"><p>Just like controller views, you can also have mailer layouts. The layout needs end in _mailer to be automatically recognized by your mailer as a layout. So in our UserMailer example, we need to call our layout user_mailer.[html,txt].erb. In order to use a different file just use:</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 2.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> UserMailer <span style="color: #990000">&lt;</span> ActionMailer<span style="color: #990000">::</span>Base
+
+ layout <span style="color: #FF0000">'awesome'</span> <span style="font-style: italic"><span style="color: #9A1900"># will use awesome.html.erb as the layout</span></span>
+
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
+<div class="paragraph"><p>Just like with controller views, use yield to render the view inside the layout.</p></div>
+<h3 id="_sending_multipart_emails">2.6. Sending multipart emails</h3>
+<div class="paragraph"><p>Coming soon!</p></div>
+</div>
+<h2 id="_receiving_emails">3. Receiving Emails</h2>
+<div class="sectionbody">
+</div>
+<h2 id="_using_action_mailer_helpers">4. Using Action Mailer Helpers</h2>
+<div class="sectionbody">
+</div>
+<h2 id="_action_mailer_configuration">5. Action Mailer Configuration</h2>
+<div class="sectionbody">
+<div class="paragraph"><p>The following configuration options are best made in one of the environment files (environment.rb, production.rb, etc...)</p></div>
+<div class="tableblock">
+<table rules="all"
+width="100%"
+frame="border"
+cellspacing="0" cellpadding="4">
+<col width="20%" />
+<col width="80%" />
+<tbody valign="top">
+<tr>
+<td align="left"><p class="table">template_root</p></td>
+<td align="left"><div><div class="paragraph"><p>Determines the base from which template references will be made.</p></div></div></td>
+</tr>
+<tr>
+<td align="left"><p class="table">logger</p></td>
+<td align="left"><div><div class="paragraph"><p>the logger is used for generating information on the mailing run if available.
+ Can be set to nil for no logging. Compatible with both Ruby&#8217;s own Logger and Log4r loggers.</p></div></div></td>
+</tr>
+<tr>
+<td align="left"><p class="table">smtp_settings</p></td>
+<td align="left"><div><div class="paragraph"><p>Allows detailed configuration for :smtp delivery method:</p></div>
+<div class="tableblock">
+<table rules="all"
+width="100%"
+frame="border"
+cellspacing="0" cellpadding="4">
+<col width="20%" />
+<col width="80%" />
+<tbody valign="top">
+<tr>
+<td align="left"><p class="table">:address</p></td>
+<td align="left"><p class="table">Allows you to use a remote mail server. Just change it from its default "localhost" setting.</p></td>
+</tr>
+<tr>
+<td align="left"><p class="table">:port</p></td>
+<td align="left"><p class="table">On the off chance that your mail server doesn&#8217;t run on port 25, you can change it.</p></td>
+</tr>
+<tr>
+<td align="left"><p class="table">:domain</p></td>
+<td align="left"><p class="table">If you need to specify a HELO domain, you can do it here.</p></td>
+</tr>
+<tr>
+<td align="left"><p class="table">:user_name</p></td>
+<td align="left"><p class="table">If your mail server requires authentication, set the username in this setting.</p></td>
+</tr>
+<tr>
+<td align="left"><p class="table">:password</p></td>
+<td align="left"><p class="table">If your mail server requires authentication, set the password in this setting.</p></td>
+</tr>
+<tr>
+<td align="left"><p class="table">:authentication</p></td>
+<td align="left"><p class="table">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.</p></td>
+</tr>
+</tbody>
+</table>
+</div></div></td>
+</tr>
+<tr>
+<td align="left"><p class="table">sendmail_settings</p></td>
+<td align="left"><div><div class="paragraph"><p>Allows you to override options for the :sendmail delivery method.</p></div>
+<div class="tableblock">
+<table rules="all"
+width="100%"
+frame="border"
+cellspacing="0" cellpadding="4">
+<col width="20%" />
+<col width="80%" />
+<tbody valign="top">
+<tr>
+<td align="left"><p class="table">:location</p></td>
+<td align="left"><p class="table">The location of the sendmail executable. Defaults to /usr/sbin/sendmail.</p></td>
+</tr>
+<tr>
+<td align="left"><p class="table">:arguments</p></td>
+<td align="left"><p class="table">The command line arguments. Defaults to -i -t.</p></td>
+</tr>
+</tbody>
+</table>
+</div></div></td>
+</tr>
+<tr>
+<td align="left"><p class="table">raise_delivery_errors</p></td>
+<td align="left"><div><div class="paragraph"><p>Whether or not errors should be raised if the email fails to be delivered.</p></div></div></td>
+</tr>
+<tr>
+<td align="left"><p class="table">delivery_method</p></td>
+<td align="left"><div><div class="paragraph"><p>Defines a delivery method. Possible values are :smtp (default), :sendmail, and :test.</p></div></div></td>
+</tr>
+<tr>
+<td align="left"><p class="table">perform_deliveries</p></td>
+<td align="left"><div><div class="paragraph"><p>Determines whether deliver_* methods are actually carried out. By default they are,
+ but this can be turned off to help functional testing.</p></div></div></td>
+</tr>
+<tr>
+<td align="left"><p class="table">deliveries</p></td>
+<td align="left"><div><div class="paragraph"><p>Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test. Most useful
+ for unit and functional testing.</p></div></div></td>
+</tr>
+<tr>
+<td align="left"><p class="table">default_charset</p></td>
+<td align="left"><div><div class="paragraph"><p>The default charset used for the body and to encode the subject. Defaults to UTF-8. You can also
+ pick a different charset from inside a method with charset.</p></div></div></td>
+</tr>
+<tr>
+<td align="left"><p class="table">default_content_type</p></td>
+<td align="left"><div><div class="paragraph"><p>The default content type used for the main part of the message. Defaults to "text/plain". You
+ can also pick a different content type from inside a method with content_type.</p></div></div></td>
+</tr>
+<tr>
+<td align="left"><p class="table">default_mime_version</p></td>
+<td align="left"><div><div class="paragraph"><p>The default mime version used for the message. Defaults to 1.0. You
+ can also pick a different value from inside a method with mime_version.</p></div></div></td>
+</tr>
+<tr>
+<td align="left"><p class="table">default_implicit_parts_order</p></td>
+<td align="left"><div><div class="paragraph"><p>When a message is built implicitly (i.e. multiple parts are assembled from templates
+ which specify the content type in their filenames) this variable controls how the parts are ordered. Defaults to
+ ["text/html", "text/enriched", "text/plain"]. Items that appear first in the array have higher priority in the mail client
+ and appear last in the mime encoded message. You can also pick a different order from inside a method with
+ implicit_parts_order.</p></div></div></td>
+</tr>
+</tbody>
+</table>
+</div>
+<h3 id="_example_action_mailer_configuration">5.1. Example Action Mailer Configuration</h3>
+<div class="paragraph"><p>An example would be:</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 2.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt>ActionMailer<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>delivery_method <span style="color: #990000">=</span> <span style="color: #990000">:</span>sendmail
+ActionMailer<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>sendmail_settings <span style="color: #990000">=</span> <span style="color: #FF0000">{</span>
+ <span style="color: #990000">:</span>location <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">'/usr/sbin/sendmail'</span><span style="color: #990000">,</span>
+ <span style="color: #990000">:</span>arguments <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">'-i -t'</span>
+<span style="color: #FF0000">}</span>
+ActionMailer<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>perform_deliveries <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #0000FF">true</span></span>
+ActionMailer<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>raise_delivery_errors <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #0000FF">true</span></span>
+ActionMailer<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>default_charset <span style="color: #990000">=</span> <span style="color: #FF0000">"iso-8859-1"</span></tt></pre></div></div>
+<h3 id="_action_mailer_configuration_for_gmail">5.2. Action Mailer Configuration for GMail</h3>
+<div class="paragraph"><p>Instructions copied from <a href="http://http://www.fromjavatoruby.com/2008/11/actionmailer-with-gmail-must-issue.html">http://http://www.fromjavatoruby.com/2008/11/actionmailer-with-gmail-must-issue.html</a></p></div>
+<div class="paragraph"><p>First you must install the action_mailer_tls plugin from <a href="http://code.openrain.com/rails/action_mailer_tls/">http://code.openrain.com/rails/action_mailer_tls/</a>, then all you have to do is configure action mailer.</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 2.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt>ActionMailer<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>smtp_settings <span style="color: #990000">=</span> <span style="color: #FF0000">{</span>
+ <span style="color: #990000">:</span>address <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"smtp.gmail.com"</span><span style="color: #990000">,</span>
+ <span style="color: #990000">:</span>port <span style="color: #990000">=&gt;</span> <span style="color: #993399">587</span><span style="color: #990000">,</span>
+ <span style="color: #990000">:</span>domain <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"domain.com"</span><span style="color: #990000">,</span>
+ <span style="color: #990000">:</span>user_name <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"user@domain.com"</span><span style="color: #990000">,</span>
+ <span style="color: #990000">:</span>password <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"password"</span><span style="color: #990000">,</span>
+ <span style="color: #990000">:</span>authentication <span style="color: #990000">=&gt;</span> <span style="color: #990000">:</span>plain
+<span style="color: #FF0000">}</span></tt></pre></div></div>
+<h3 id="_configure_action_mailer_to_recognize_haml_templates">5.3. Configure Action Mailer to recognize HAML templates</h3>
+<div class="paragraph"><p>In environment.rb, add the following line:</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 2.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt>ActionMailer<span style="color: #990000">::</span>Base<span style="color: #990000">.</span>register_template_extension<span style="color: #990000">(</span><span style="color: #FF0000">'haml'</span><span style="color: #990000">)</span></tt></pre></div></div>
</div>
-<h2 id="_mailer_testing">3. Mailer Testing</h2>
+<h2 id="_mailer_testing">6. Mailer Testing</h2>
<div class="sectionbody">
<div class="paragraph"><p>Testing mailers involves 2 things. One is that the mail was queued and the other that the body contains what we expect it to contain. With that in mind, we could test our example mailer from above like so:</p></div>
<div class="listingblock">
@@ -219,11 +543,11 @@ http://www.gnu.org/software/src-highlite -->
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
<div class="paragraph"><p>What have we done? Well, we sent the email and stored the returned object in the email variable. We then ensured that it was sent (the first assert), then, in the second batch of assertion, we ensure that the email does indeed contain the values that we expect.</p></div>
</div>
-<h2 id="_epilogue">4. Epilogue</h2>
+<h2 id="_epilogue">7. Epilogue</h2>
<div class="sectionbody">
<div class="paragraph"><p>This guide presented how to create a mailer and how to test it. In reality, you may find that writing your tests before you actually write your code to be a rewarding experience. It may take some time to get used to TDD (Test Driven Development), but coding this way achieves two major benefits. Firstly, you know that the code does indeed work, because the tests fail (because there&#8217;s no code), then they pass, because the code that satisfies the tests was written. Secondly, when you start with the tests, you don&#8217;t have to make time AFTER you write the code, to write the tests, then never get around to it. The tests are already there and testing has now become part of your coding regimen.</p></div>
</div>
-<h2 id="_changelog">5. Changelog</h2>
+<h2 id="_changelog">8. Changelog</h2>
<div class="sectionbody">
<div class="paragraph"><p><a href="http://rails.lighthouseapp.com/projects/16213/tickets/25">Lighthouse ticket</a></p></div>
</div>