rails 4.2.0.beta3 → 4.2.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -7
  3. data/guides/output/2_2_release_notes.html +724 -0
  4. data/guides/output/2_3_release_notes.html +870 -0
  5. data/guides/output/3_0_release_notes.html +773 -0
  6. data/guides/output/3_1_release_notes.html +740 -0
  7. data/guides/output/3_2_release_notes.html +797 -0
  8. data/guides/output/4_0_release_notes.html +523 -0
  9. data/guides/output/4_1_release_notes.html +806 -0
  10. data/guides/output/4_2_release_notes.html +728 -0
  11. data/guides/output/Gemfile +6 -0
  12. data/guides/output/_license.html +226 -0
  13. data/guides/output/_welcome.html +233 -0
  14. data/guides/output/action_controller_overview.html +1335 -0
  15. data/guides/output/action_mailer_basics.html +928 -0
  16. data/guides/output/action_view_overview.html +1509 -0
  17. data/guides/output/active_job_basics.html +546 -0
  18. data/guides/output/active_model_basics.html +438 -0
  19. data/guides/output/active_record_basics.html +594 -0
  20. data/guides/output/active_record_callbacks.html +592 -0
  21. data/guides/output/active_record_migrations.html +1123 -0
  22. data/guides/output/active_record_postgresql.html +675 -0
  23. data/guides/output/active_record_querying.html +1796 -0
  24. data/guides/output/active_record_validations.html +1301 -0
  25. data/guides/output/active_support_core_extensions.html +3450 -0
  26. data/guides/output/active_support_instrumentation.html +1121 -0
  27. data/guides/output/api_documentation_guidelines.html +498 -0
  28. data/guides/output/asset_pipeline.html +1167 -0
  29. data/guides/output/association_basics.html +2086 -0
  30. data/guides/output/caching_with_rails.html +553 -0
  31. data/guides/output/command_line.html +791 -0
  32. data/guides/output/configuring.html +1055 -0
  33. data/guides/output/contributing_to_ruby_on_rails.html +657 -0
  34. data/guides/output/credits.html +284 -0
  35. data/guides/output/debugging_rails_applications.html +1014 -0
  36. data/guides/output/development_dependencies_install.html +478 -0
  37. data/guides/output/engines.html +1438 -0
  38. data/guides/output/form_helpers.html +1074 -0
  39. data/guides/output/generators.html +838 -0
  40. data/guides/output/getting_started.html +2092 -0
  41. data/guides/output/i18n.html +1198 -0
  42. data/guides/output/images/akshaysurve.jpg +0 -0
  43. data/guides/output/images/belongs_to.png +0 -0
  44. data/guides/output/images/book_icon.gif +0 -0
  45. data/guides/output/images/bullet.gif +0 -0
  46. data/guides/output/images/chapters_icon.gif +0 -0
  47. data/guides/output/images/check_bullet.gif +0 -0
  48. data/guides/output/images/credits_pic_blank.gif +0 -0
  49. data/guides/output/images/csrf.png +0 -0
  50. data/guides/output/images/edge_badge.png +0 -0
  51. data/guides/output/images/favicon.ico +0 -0
  52. data/guides/output/images/feature_tile.gif +0 -0
  53. data/guides/output/images/footer_tile.gif +0 -0
  54. data/guides/output/images/fxn.png +0 -0
  55. data/guides/output/images/getting_started/article_with_comments.png +0 -0
  56. data/guides/output/images/getting_started/challenge.png +0 -0
  57. data/guides/output/images/getting_started/confirm_dialog.png +0 -0
  58. data/guides/output/images/getting_started/forbidden_attributes_for_new_article.png +0 -0
  59. data/guides/output/images/getting_started/forbidden_attributes_for_new_post.png +0 -0
  60. data/guides/output/images/getting_started/form_with_errors.png +0 -0
  61. data/guides/output/images/getting_started/index_action_with_edit_link.png +0 -0
  62. data/guides/output/images/getting_started/new_article.png +0 -0
  63. data/guides/output/images/getting_started/new_post.png +0 -0
  64. data/guides/output/images/getting_started/post_with_comments.png +0 -0
  65. data/guides/output/images/getting_started/rails_welcome.png +0 -0
  66. data/guides/output/images/getting_started/routing_error_no_controller.png +0 -0
  67. data/guides/output/images/getting_started/routing_error_no_route_matches.png +0 -0
  68. data/guides/output/images/getting_started/show_action_for_articles.png +0 -0
  69. data/guides/output/images/getting_started/show_action_for_posts.png +0 -0
  70. data/guides/output/images/getting_started/template_is_missing_articles_new.png +0 -0
  71. data/guides/output/images/getting_started/template_is_missing_posts_new.png +0 -0
  72. data/guides/output/images/getting_started/undefined_method_post_path.png +0 -0
  73. data/guides/output/images/getting_started/unknown_action_create_for_articles.png +0 -0
  74. data/guides/output/images/getting_started/unknown_action_create_for_posts.png +0 -0
  75. data/guides/output/images/getting_started/unknown_action_new_for_articles.png +0 -0
  76. data/guides/output/images/getting_started/unknown_action_new_for_posts.png +0 -0
  77. data/guides/output/images/grey_bullet.gif +0 -0
  78. data/guides/output/images/habtm.png +0 -0
  79. data/guides/output/images/has_many.png +0 -0
  80. data/guides/output/images/has_many_through.png +0 -0
  81. data/guides/output/images/has_one.png +0 -0
  82. data/guides/output/images/has_one_through.png +0 -0
  83. data/guides/output/images/header_backdrop.png +0 -0
  84. data/guides/output/images/header_tile.gif +0 -0
  85. data/guides/output/images/i18n/demo_html_safe.png +0 -0
  86. data/guides/output/images/i18n/demo_localized_pirate.png +0 -0
  87. data/guides/output/images/i18n/demo_translated_en.png +0 -0
  88. data/guides/output/images/i18n/demo_translated_pirate.png +0 -0
  89. data/guides/output/images/i18n/demo_translation_missing.png +0 -0
  90. data/guides/output/images/i18n/demo_untranslated.png +0 -0
  91. data/guides/output/images/icons/README +5 -0
  92. data/guides/output/images/icons/callouts/1.png +0 -0
  93. data/guides/output/images/icons/callouts/10.png +0 -0
  94. data/guides/output/images/icons/callouts/11.png +0 -0
  95. data/guides/output/images/icons/callouts/12.png +0 -0
  96. data/guides/output/images/icons/callouts/13.png +0 -0
  97. data/guides/output/images/icons/callouts/14.png +0 -0
  98. data/guides/output/images/icons/callouts/15.png +0 -0
  99. data/guides/output/images/icons/callouts/2.png +0 -0
  100. data/guides/output/images/icons/callouts/3.png +0 -0
  101. data/guides/output/images/icons/callouts/4.png +0 -0
  102. data/guides/output/images/icons/callouts/5.png +0 -0
  103. data/guides/output/images/icons/callouts/6.png +0 -0
  104. data/guides/output/images/icons/callouts/7.png +0 -0
  105. data/guides/output/images/icons/callouts/8.png +0 -0
  106. data/guides/output/images/icons/callouts/9.png +0 -0
  107. data/guides/output/images/icons/caution.png +0 -0
  108. data/guides/output/images/icons/example.png +0 -0
  109. data/guides/output/images/icons/home.png +0 -0
  110. data/guides/output/images/icons/important.png +0 -0
  111. data/guides/output/images/icons/next.png +0 -0
  112. data/guides/output/images/icons/note.png +0 -0
  113. data/guides/output/images/icons/prev.png +0 -0
  114. data/guides/output/images/icons/tip.png +0 -0
  115. data/guides/output/images/icons/up.png +0 -0
  116. data/guides/output/images/icons/warning.png +0 -0
  117. data/guides/output/images/nav_arrow.gif +0 -0
  118. data/guides/output/images/oscardelben.jpg +0 -0
  119. data/guides/output/images/polymorphic.png +0 -0
  120. data/guides/output/images/radar.png +0 -0
  121. data/guides/output/images/rails4_features.png +0 -0
  122. data/guides/output/images/rails_guides_kindle_cover.jpg +0 -0
  123. data/guides/output/images/rails_guides_logo.gif +0 -0
  124. data/guides/output/images/rails_logo_remix.gif +0 -0
  125. data/guides/output/images/session_fixation.png +0 -0
  126. data/guides/output/images/tab_grey.gif +0 -0
  127. data/guides/output/images/tab_info.gif +0 -0
  128. data/guides/output/images/tab_note.gif +0 -0
  129. data/guides/output/images/tab_red.gif +0 -0
  130. data/guides/output/images/tab_yellow.gif +0 -0
  131. data/guides/output/images/tab_yellow.png +0 -0
  132. data/guides/output/images/vijaydev.jpg +0 -0
  133. data/guides/output/index.html +354 -0
  134. data/guides/output/initialization.html +876 -0
  135. data/guides/output/javascripts/guides.js +59 -0
  136. data/guides/output/javascripts/jquery.min.js +4 -0
  137. data/guides/output/javascripts/responsive-tables.js +43 -0
  138. data/guides/output/javascripts/syntaxhighlighter/shBrushAS3.js +59 -0
  139. data/guides/output/javascripts/syntaxhighlighter/shBrushAppleScript.js +75 -0
  140. data/guides/output/javascripts/syntaxhighlighter/shBrushBash.js +59 -0
  141. data/guides/output/javascripts/syntaxhighlighter/shBrushCSharp.js +65 -0
  142. data/guides/output/javascripts/syntaxhighlighter/shBrushColdFusion.js +100 -0
  143. data/guides/output/javascripts/syntaxhighlighter/shBrushCpp.js +97 -0
  144. data/guides/output/javascripts/syntaxhighlighter/shBrushCss.js +91 -0
  145. data/guides/output/javascripts/syntaxhighlighter/shBrushDelphi.js +55 -0
  146. data/guides/output/javascripts/syntaxhighlighter/shBrushDiff.js +41 -0
  147. data/guides/output/javascripts/syntaxhighlighter/shBrushErlang.js +52 -0
  148. data/guides/output/javascripts/syntaxhighlighter/shBrushGroovy.js +67 -0
  149. data/guides/output/javascripts/syntaxhighlighter/shBrushJScript.js +52 -0
  150. data/guides/output/javascripts/syntaxhighlighter/shBrushJava.js +57 -0
  151. data/guides/output/javascripts/syntaxhighlighter/shBrushJavaFX.js +58 -0
  152. data/guides/output/javascripts/syntaxhighlighter/shBrushPerl.js +72 -0
  153. data/guides/output/javascripts/syntaxhighlighter/shBrushPhp.js +88 -0
  154. data/guides/output/javascripts/syntaxhighlighter/shBrushPlain.js +33 -0
  155. data/guides/output/javascripts/syntaxhighlighter/shBrushPowerShell.js +74 -0
  156. data/guides/output/javascripts/syntaxhighlighter/shBrushPython.js +64 -0
  157. data/guides/output/javascripts/syntaxhighlighter/shBrushRuby.js +55 -0
  158. data/guides/output/javascripts/syntaxhighlighter/shBrushSass.js +94 -0
  159. data/guides/output/javascripts/syntaxhighlighter/shBrushScala.js +51 -0
  160. data/guides/output/javascripts/syntaxhighlighter/shBrushSql.js +66 -0
  161. data/guides/output/javascripts/syntaxhighlighter/shBrushVb.js +56 -0
  162. data/guides/output/javascripts/syntaxhighlighter/shBrushXml.js +69 -0
  163. data/guides/output/javascripts/syntaxhighlighter/shCore.js +17 -0
  164. data/guides/output/layout.html +448 -0
  165. data/guides/output/layouts_and_rendering.html +1541 -0
  166. data/guides/output/maintenance_policy.html +257 -0
  167. data/guides/output/migrations.html +1360 -0
  168. data/guides/output/nested_model_forms.html +412 -0
  169. data/guides/output/plugins.html +644 -0
  170. data/guides/output/rails_application_templates.html +450 -0
  171. data/guides/output/rails_on_rack.html +547 -0
  172. data/guides/output/routing.html +1631 -0
  173. data/guides/output/ruby_on_rails_guides_guidelines.html +329 -0
  174. data/guides/output/security.html +935 -0
  175. data/guides/output/stylesheets/fixes.css +16 -0
  176. data/guides/output/stylesheets/kindle.css +11 -0
  177. data/guides/output/stylesheets/main.css +713 -0
  178. data/guides/output/stylesheets/print.css +52 -0
  179. data/guides/output/stylesheets/reset.css +43 -0
  180. data/guides/output/stylesheets/responsive-tables.css +50 -0
  181. data/guides/output/stylesheets/style.css +13 -0
  182. data/guides/output/stylesheets/syntaxhighlighter/shCore.css +226 -0
  183. data/guides/output/stylesheets/syntaxhighlighter/shCoreDefault.css +328 -0
  184. data/guides/output/stylesheets/syntaxhighlighter/shCoreDjango.css +331 -0
  185. data/guides/output/stylesheets/syntaxhighlighter/shCoreEclipse.css +339 -0
  186. data/guides/output/stylesheets/syntaxhighlighter/shCoreEmacs.css +324 -0
  187. data/guides/output/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +328 -0
  188. data/guides/output/stylesheets/syntaxhighlighter/shCoreMDUltra.css +324 -0
  189. data/guides/output/stylesheets/syntaxhighlighter/shCoreMidnight.css +324 -0
  190. data/guides/output/stylesheets/syntaxhighlighter/shCoreRDark.css +324 -0
  191. data/guides/output/stylesheets/syntaxhighlighter/shThemeDefault.css +117 -0
  192. data/guides/output/stylesheets/syntaxhighlighter/shThemeDjango.css +120 -0
  193. data/guides/output/stylesheets/syntaxhighlighter/shThemeEclipse.css +128 -0
  194. data/guides/output/stylesheets/syntaxhighlighter/shThemeEmacs.css +113 -0
  195. data/guides/output/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +117 -0
  196. data/guides/output/stylesheets/syntaxhighlighter/shThemeMDUltra.css +113 -0
  197. data/guides/output/stylesheets/syntaxhighlighter/shThemeMidnight.css +113 -0
  198. data/guides/output/stylesheets/syntaxhighlighter/shThemeRDark.css +113 -0
  199. data/guides/output/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +116 -0
  200. data/guides/output/testing.html +1350 -0
  201. data/guides/output/upgrading_ruby_on_rails.html +1135 -0
  202. data/guides/output/working_with_javascript_in_rails.html +587 -0
  203. data/guides/source/4_0_release_notes.md +2 -2
  204. data/guides/source/4_2_release_notes.md +9 -2
  205. data/guides/source/action_controller_overview.md +3 -1
  206. data/guides/source/action_mailer_basics.md +1 -2
  207. data/guides/source/active_job_basics.md +25 -2
  208. data/guides/source/active_model_basics.md +350 -19
  209. data/guides/source/active_record_basics.md +2 -2
  210. data/guides/source/active_record_migrations.md +1 -1
  211. data/guides/source/active_record_validations.md +12 -4
  212. data/guides/source/active_support_core_extensions.md +7 -9
  213. data/guides/source/active_support_instrumentation.md +2 -0
  214. data/guides/source/association_basics.md +7 -7
  215. data/guides/source/configuring.md +24 -0
  216. data/guides/source/contributing_to_ruby_on_rails.md +1 -1
  217. data/guides/source/credits.html.erb +1 -1
  218. data/guides/source/documents.yaml +5 -0
  219. data/guides/source/engines.md +2 -2
  220. data/guides/source/form_helpers.md +6 -0
  221. data/guides/source/i18n.md +6 -9
  222. data/guides/source/layouts_and_rendering.md +1 -1
  223. data/guides/source/plugins.md +2 -2
  224. data/guides/source/rails_on_rack.md +4 -0
  225. data/guides/source/testing.md +1 -0
  226. data/guides/source/upgrading_ruby_on_rails.md +5 -5
  227. metadata +227 -27
@@ -0,0 +1,928 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1"/>
7
+
8
+ <title>Action Mailer Basics — Ruby on Rails Guides</title>
9
+ <link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
10
+ <link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
11
+
12
+ <link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" />
13
+ <link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shThemeRailsGuides.css" />
14
+
15
+ <link rel="stylesheet" type="text/css" href="stylesheets/fixes.css" />
16
+
17
+ <link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
18
+ </head>
19
+ <body class="guide">
20
+ <div id="topNav">
21
+ <div class="wrapper">
22
+ <strong class="more-info-label">More at <a href="http://rubyonrails.org/">rubyonrails.org:</a> </strong>
23
+ <span class="red-button more-info-button">
24
+ More Ruby on Rails
25
+ </span>
26
+ <ul class="more-info-links s-hidden">
27
+ <li class="more-info"><a href="http://rubyonrails.org/">Overview</a></li>
28
+ <li class="more-info"><a href="http://rubyonrails.org/download">Download</a></li>
29
+ <li class="more-info"><a href="http://rubyonrails.org/deploy">Deploy</a></li>
30
+ <li class="more-info"><a href="https://github.com/rails/rails">Code</a></li>
31
+ <li class="more-info"><a href="http://rubyonrails.org/screencasts">Screencasts</a></li>
32
+ <li class="more-info"><a href="http://rubyonrails.org/documentation">Documentation</a></li>
33
+ <li class="more-info"><a href="http://rubyonrails.org/community">Community</a></li>
34
+ <li class="more-info"><a href="http://weblog.rubyonrails.org/">Blog</a></li>
35
+ </ul>
36
+ </div>
37
+ </div>
38
+ <div id="header">
39
+ <div class="wrapper clearfix">
40
+ <h1><a href="index.html" title="Return to home page">Guides.rubyonrails.org</a></h1>
41
+ <ul class="nav">
42
+ <li><a class="nav-item" href="index.html">Home</a></li>
43
+ <li class="guides-index guides-index-large">
44
+ <a href="index.html" id="guidesMenu" class="guides-index-item nav-item">Guides Index</a>
45
+ <div id="guides" class="clearfix" style="display: none;">
46
+ <hr />
47
+ <dl class="L">
48
+ <dt>Start Here</dt>
49
+ <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
50
+ <dt>Models</dt>
51
+ <dd><a href="active_record_basics.html">Active Record Basics</a></dd>
52
+ <dd><a href="active_record_migrations.html">Active Record Migrations</a></dd>
53
+ <dd><a href="active_record_validations.html">Active Record Validations</a></dd>
54
+ <dd><a href="active_record_callbacks.html">Active Record Callbacks</a></dd>
55
+ <dd><a href="association_basics.html">Active Record Associations</a></dd>
56
+ <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
57
+ <dt>Views</dt>
58
+ <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd>
59
+ <dd><a href="form_helpers.html">Action View Form Helpers</a></dd>
60
+ <dt>Controllers</dt>
61
+ <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd>
62
+ <dd><a href="routing.html">Rails Routing from the Outside In</a></dd>
63
+ </dl>
64
+ <dl class="R">
65
+ <dt>Digging Deeper</dt>
66
+ <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd>
67
+ <dd><a href="i18n.html">Rails Internationalization API</a></dd>
68
+ <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd>
69
+ <dd><a href="active_job_basics.html">Active Job Basics</a></dd>
70
+ <dd><a href="security.html">Securing Rails Applications</a></dd>
71
+ <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd>
72
+ <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
73
+ <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
74
+ <dd><a href="asset_pipeline.html">Asset Pipeline</a></dd>
75
+ <dd><a href="working_with_javascript_in_rails.html">Working with JavaScript in Rails</a></dd>
76
+ <dt>Extending Rails</dt>
77
+ <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
78
+ <dd><a href="generators.html">Creating and Customizing Rails Generators</a></dd>
79
+ <dt>Contributing to Ruby on Rails</dt>
80
+ <dd><a href="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</a></dd>
81
+ <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
82
+ <dd><a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a></dd>
83
+ <dt>Maintenance Policy</dt>
84
+ <dd><a href="maintenance_policy.html">Maintenance Policy</a></dd>
85
+ <dt>Release Notes</dt>
86
+ <dd><a href="upgrading_ruby_on_rails.html">Upgrading Ruby on Rails</a></dd>
87
+ <dd><a href="4_1_release_notes.html">Ruby on Rails 4.1 Release Notes</a></dd>
88
+ <dd><a href="4_0_release_notes.html">Ruby on Rails 4.0 Release Notes</a></dd>
89
+ <dd><a href="3_2_release_notes.html">Ruby on Rails 3.2 Release Notes</a></dd>
90
+ <dd><a href="3_1_release_notes.html">Ruby on Rails 3.1 Release Notes</a></dd>
91
+ <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
92
+ <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
93
+ <dd><a href="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</a></dd>
94
+ </dl>
95
+ </div>
96
+ </li>
97
+ <li><a class="nav-item" href="contributing_to_ruby_on_rails.html">Contribute</a></li>
98
+ <li><a class="nav-item" href="credits.html">Credits</a></li>
99
+ <li class="guides-index guides-index-small">
100
+ <select class="guides-index-item nav-item">
101
+ <option value="index.html">Guides Index</option>
102
+ <optgroup label="Start Here">
103
+ <option value="getting_started.html">Getting Started with Rails</option>
104
+ </optgroup>
105
+ <optgroup label="Models">
106
+ <option value="active_record_basics.html">Active Record Basics</option>
107
+ <option value="active_record_migrations.html">Active Record Migrations</option>
108
+ <option value="active_record_validations.html">Active Record Validations</option>
109
+ <option value="active_record_callbacks.html">Active Record Callbacks</option>
110
+ <option value="association_basics.html">Active Record Associations</option>
111
+ <option value="active_record_querying.html">Active Record Query Interface</option>
112
+ </optgroup>
113
+ <optgroup label="Views">
114
+ <option value="layouts_and_rendering.html">Layouts and Rendering in Rails</option>
115
+ <option value="form_helpers.html">Action View Form Helpers</option>
116
+ </optgroup>
117
+ <optgroup label="Controllers">
118
+ <option value="action_controller_overview.html">Action Controller Overview</option>
119
+ <option value="routing.html">Rails Routing from the Outside In</option>
120
+ </optgroup>
121
+ <optgroup label="Digging Deeper">
122
+ <option value="active_support_core_extensions.html">Active Support Core Extensions</option>
123
+ <option value="i18n.html">Rails Internationalization API</option>
124
+ <option value="action_mailer_basics.html">Action Mailer Basics</option>
125
+ <option value="active_job_basics.html">Active Job Basics</option>
126
+ <option value="security.html">Securing Rails Applications</option>
127
+ <option value="debugging_rails_applications.html">Debugging Rails Applications</option>
128
+ <option value="configuring.html">Configuring Rails Applications</option>
129
+ <option value="command_line.html">Rails Command Line Tools and Rake Tasks</option>
130
+ <option value="asset_pipeline.html">Asset Pipeline</option>
131
+ <option value="working_with_javascript_in_rails.html">Working with JavaScript in Rails</option>
132
+ </optgroup>
133
+ <optgroup label="Extending Rails">
134
+ <option value="rails_on_rack.html">Rails on Rack</option>
135
+ <option value="generators.html">Creating and Customizing Rails Generators</option>
136
+ </optgroup>
137
+ <optgroup label="Contributing to Ruby on Rails">
138
+ <option value="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</option>
139
+ <option value="api_documentation_guidelines.html">API Documentation Guidelines</option>
140
+ <option value="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</option>
141
+ </optgroup>
142
+ <optgroup label="Maintenance Policy">
143
+ <option value="maintenance_policy.html">Maintenance Policy</option>
144
+ </optgroup>
145
+ <optgroup label="Release Notes">
146
+ <option value="upgrading_ruby_on_rails.html">Upgrading Ruby on Rails</option>
147
+ <option value="4_1_release_notes.html">Ruby on Rails 4.1 Release Notes</option>
148
+ <option value="4_0_release_notes.html">Ruby on Rails 4.0 Release Notes</option>
149
+ <option value="3_2_release_notes.html">Ruby on Rails 3.2 Release Notes</option>
150
+ <option value="3_1_release_notes.html">Ruby on Rails 3.1 Release Notes</option>
151
+ <option value="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</option>
152
+ <option value="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</option>
153
+ <option value="2_2_release_notes.html">Ruby on Rails 2.2 Release Notes</option>
154
+ </optgroup>
155
+ </select>
156
+ </li>
157
+ </ul>
158
+ </div>
159
+ </div>
160
+ <hr class="hide" />
161
+
162
+ <div id="feature">
163
+ <div class="wrapper">
164
+ <h2>Action Mailer Basics</h2><p>This guide provides you with all you need to get started in sending and
165
+ receiving emails from and to your application, and many internals of Action
166
+ Mailer. It also covers how to test your mailers.</p><p>After reading this guide, you will know:</p>
167
+ <ul>
168
+ <li>How to send and receive email within a Rails application.</li>
169
+ <li>How to generate and edit an Action Mailer class and mailer view.</li>
170
+ <li>How to configure Action Mailer for your environment.</li>
171
+ <li>How to test your Action Mailer classes.</li>
172
+ </ul>
173
+
174
+
175
+ <div id="subCol">
176
+ <h3 class="chapter"><img src="images/chapters_icon.gif" alt="" />Chapters</h3>
177
+ <ol class="chapters">
178
+ <li><a href="#introduction">Introduction</a></li>
179
+ <li>
180
+ <a href="#sending-emails">Sending Emails</a>
181
+
182
+ <ul>
183
+ <li><a href="#walkthrough-to-generating-a-mailer">Walkthrough to Generating a Mailer</a></li>
184
+ <li><a href="#auto-encoding-header-values">Auto encoding header values</a></li>
185
+ <li><a href="#complete-list-of-action-mailer-methods">Complete List of Action Mailer Methods</a></li>
186
+ <li><a href="#mailer-views">Mailer Views</a></li>
187
+ <li><a href="#action-mailer-layouts">Action Mailer Layouts</a></li>
188
+ <li><a href="#generating-urls-in-action-mailer-views">Generating URLs in Action Mailer Views</a></li>
189
+ <li><a href="#sending-multipart-emails">Sending Multipart Emails</a></li>
190
+ <li><a href="#sending-emails-with-dynamic-delivery-options">Sending Emails with Dynamic Delivery Options</a></li>
191
+ <li><a href="#sending-emails-without-template-rendering">Sending Emails without Template Rendering</a></li>
192
+ </ul>
193
+ </li>
194
+ <li><a href="#receiving-emails">Receiving Emails</a></li>
195
+ <li><a href="#action-mailer-callbacks">Action Mailer Callbacks</a></li>
196
+ <li><a href="#using-action-mailer-helpers">Using Action Mailer Helpers</a></li>
197
+ <li>
198
+ <a href="#action-mailer-configuration">Action Mailer Configuration</a>
199
+
200
+ <ul>
201
+ <li><a href="#example-action-mailer-configuration">Example Action Mailer Configuration</a></li>
202
+ <li><a href="#action-mailer-configuration-for-gmail">Action Mailer Configuration for Gmail</a></li>
203
+ </ul>
204
+ </li>
205
+ <li><a href="#mailer-testing">Mailer Testing</a></li>
206
+ <li><a href="#intercepting-emails">Intercepting Emails</a></li>
207
+ </ol>
208
+
209
+ </div>
210
+
211
+ </div>
212
+ </div>
213
+
214
+ <div id="container">
215
+ <div class="wrapper">
216
+ <div id="mainCol">
217
+ <h3 id="introduction">1 Introduction</h3><p>Action Mailer allows you to send emails from your application using mailer classes
218
+ and views. Mailers work very similarly to controllers. They inherit from
219
+ <code>ActionMailer::Base</code> and live in <code>app/mailers</code>, and they have associated views
220
+ that appear in <code>app/views</code>.</p><h3 id="sending-emails">2 Sending Emails</h3><p>This section will provide a step-by-step guide to creating a mailer and its
221
+ views.</p><h4 id="walkthrough-to-generating-a-mailer">2.1 Walkthrough to Generating a Mailer</h4><h5 id="create-the-mailer">2.1.1 Create the Mailer</h5><div class="code_container">
222
+ <pre class="brush: plain; gutter: false; toolbar: false">
223
+ $ bin/rails generate mailer UserMailer
224
+ create app/mailers/user_mailer.rb
225
+ invoke erb
226
+ create app/views/user_mailer
227
+ invoke test_unit
228
+ create test/mailers/user_mailer_test.rb
229
+
230
+ </pre>
231
+ </div>
232
+ <p>As you can see, you can generate mailers just like you use other generators with
233
+ Rails. Mailers are conceptually similar to controllers, and so we get a mailer,
234
+ a directory for views, and a test.</p><p>If you didn't want to use a generator, you could create your own file inside of
235
+ app/mailers, just make sure that it inherits from <code>ActionMailer::Base</code>:</p><div class="code_container">
236
+ <pre class="brush: ruby; gutter: false; toolbar: false">
237
+ class MyMailer &lt; ActionMailer::Base
238
+ end
239
+
240
+ </pre>
241
+ </div>
242
+ <h5 id="edit-the-mailer">2.1.2 Edit the Mailer</h5><p>Mailers are very similar to Rails controllers. They also have methods called
243
+ "actions" and use views to structure the content. Where a controller generates
244
+ content like HTML to send back to the client, a Mailer creates a message to be
245
+ delivered via email.</p><p><code>app/mailers/user_mailer.rb</code> contains an empty mailer:</p><div class="code_container">
246
+ <pre class="brush: ruby; gutter: false; toolbar: false">
247
+ class UserMailer &lt; ActionMailer::Base
248
+ default from: 'from@example.com'
249
+ end
250
+
251
+ </pre>
252
+ </div>
253
+ <p>Let's add a method called <code>welcome_email</code>, that will send an email to the user's
254
+ registered email address:</p><div class="code_container">
255
+ <pre class="brush: ruby; gutter: false; toolbar: false">
256
+ class UserMailer &lt; ActionMailer::Base
257
+ default from: 'notifications@example.com'
258
+
259
+ def welcome_email(user)
260
+ @user = user
261
+ @url = 'http://example.com/login'
262
+ mail(to: @user.email, subject: 'Welcome to My Awesome Site')
263
+ end
264
+ end
265
+
266
+ </pre>
267
+ </div>
268
+ <p>Here is a quick explanation of the items presented in the preceding method. For
269
+ a full list of all available options, please have a look further down at the
270
+ Complete List of Action Mailer user-settable attributes section.</p>
271
+ <ul>
272
+ <li>
273
+ <code>default Hash</code> - This is a hash of default values for any email you send from
274
+ this mailer. In this case we are setting the <code>:from</code> header to a value for all
275
+ messages in this class. This can be overridden on a per-email basis.</li>
276
+ <li>
277
+ <code>mail</code> - The actual email message, we are passing the <code>:to</code> and <code>:subject</code>
278
+ headers in.</li>
279
+ </ul>
280
+ <p>Just like controllers, any instance variables we define in the method become
281
+ available for use in the views.</p><h5 id="create-a-mailer-view">2.1.3 Create a Mailer View</h5><p>Create a file called <code>welcome_email.html.erb</code> in <code>app/views/user_mailer/</code>. This
282
+ will be the template used for the email, formatted in HTML:</p><div class="code_container">
283
+ <pre class="brush: plain; gutter: false; toolbar: false">
284
+ &lt;!DOCTYPE html&gt;
285
+ &lt;html&gt;
286
+ &lt;head&gt;
287
+ &lt;meta content='text/html; charset=UTF-8' http-equiv='Content-Type' /&gt;
288
+ &lt;/head&gt;
289
+ &lt;body&gt;
290
+ &lt;h1&gt;Welcome to example.com, &lt;%= @user.name %&gt;&lt;/h1&gt;
291
+ &lt;p&gt;
292
+ You have successfully signed up to example.com,
293
+ your username is: &lt;%= @user.login %&gt;.&lt;br&gt;
294
+ &lt;/p&gt;
295
+ &lt;p&gt;
296
+ To login to the site, just follow this link: &lt;%= @url %&gt;.
297
+ &lt;/p&gt;
298
+ &lt;p&gt;Thanks for joining and have a great day!&lt;/p&gt;
299
+ &lt;/body&gt;
300
+ &lt;/html&gt;
301
+
302
+ </pre>
303
+ </div>
304
+ <p>Let's also make a text part for this email. Not all clients prefer HTML emails,
305
+ and so sending both is best practice. To do this, create a file called
306
+ <code>welcome_email.text.erb</code> in <code>app/views/user_mailer/</code>:</p><div class="code_container">
307
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
308
+ Welcome to example.com, &lt;%= @user.name %&gt;
309
+ ===============================================
310
+
311
+ You have successfully signed up to example.com,
312
+ your username is: &lt;%= @user.login %&gt;.
313
+
314
+ To login to the site, just follow this link: &lt;%= @url %&gt;.
315
+
316
+ Thanks for joining and have a great day!
317
+
318
+ </pre>
319
+ </div>
320
+ <p>When you call the <code>mail</code> method now, Action Mailer will detect the two templates
321
+ (text and HTML) and automatically generate a <code>multipart/alternative</code> email.</p><h5 id="calling-the-mailer">2.1.4 Calling the Mailer</h5><p>Mailers are really just another way to render a view. Instead of rendering a
322
+ view and sending out the HTTP protocol, they are just sending it out through the
323
+ email protocols instead. Due to this, it makes sense to just have your
324
+ controller tell the Mailer to send an email when a user is successfully created.</p><p>Setting this up is painfully simple.</p><p>First, let's create a simple <code>User</code> scaffold:</p><div class="code_container">
325
+ <pre class="brush: plain; gutter: false; toolbar: false">
326
+ $ bin/rails generate scaffold user name email login
327
+ $ bin/rake db:migrate
328
+
329
+ </pre>
330
+ </div>
331
+ <p>Now that we have a user model to play with, we will just edit the
332
+ <code>app/controllers/users_controller.rb</code> make it instruct the <code>UserMailer</code> to deliver
333
+ an email to the newly created user by editing the create action and inserting a
334
+ call to <code>UserMailer.welcome_email</code> right after the user is successfully saved:</p><div class="code_container">
335
+ <pre class="brush: ruby; gutter: false; toolbar: false">
336
+ class UsersController &lt; ApplicationController
337
+ # POST /users
338
+ # POST /users.json
339
+ def create
340
+ @user = User.new(params[:user])
341
+
342
+ respond_to do |format|
343
+ if @user.save
344
+ # Tell the UserMailer to send a welcome email after save
345
+ UserMailer.welcome_email(@user).deliver
346
+
347
+ format.html { redirect_to(@user, notice: 'User was successfully created.') }
348
+ format.json { render json: @user, status: :created, location: @user }
349
+ else
350
+ format.html { render action: 'new' }
351
+ format.json { render json: @user.errors, status: :unprocessable_entity }
352
+ end
353
+ end
354
+ end
355
+ end
356
+
357
+ </pre>
358
+ </div>
359
+ <p>The method <code>welcome_email</code> returns a <code>Mail::Message</code> object which can then just
360
+ be told <code>deliver</code> to send itself out.</p><h4 id="auto-encoding-header-values">2.2 Auto encoding header values</h4><p>Action Mailer handles the auto encoding of multibyte characters inside of
361
+ headers and bodies.</p><p>For more complex examples such as defining alternate character sets or
362
+ self-encoding text first, please refer to the
363
+ <a href="https://github.com/mikel/mail">Mail</a> library.</p><h4 id="complete-list-of-action-mailer-methods">2.3 Complete List of Action Mailer Methods</h4><p>There are just three methods that you need to send pretty much any email
364
+ message:</p>
365
+ <ul>
366
+ <li>
367
+ <code>headers</code> - Specifies any header on the email you want. You can pass a hash of
368
+ header field names and value pairs, or you can call <code>headers[:field_name] =
369
+ 'value'</code>.</li>
370
+ <li>
371
+ <code>attachments</code> - Allows you to add attachments to your email. For example,
372
+ <code>attachments['file-name.jpg'] = File.read('file-name.jpg')</code>.</li>
373
+ <li>
374
+ <code>mail</code> - Sends the actual email itself. You can pass in headers as a hash to
375
+ the mail method as a parameter, mail will then create an email, either plain
376
+ text, or multipart, depending on what email templates you have defined.</li>
377
+ </ul>
378
+ <h5 id="adding-attachments">2.3.1 Adding Attachments</h5><p>Action Mailer makes it very easy to add attachments.</p>
379
+ <ul>
380
+ <li>
381
+ <p>Pass the file name and content and Action Mailer and the
382
+ <a href="https://github.com/mikel/mail">Mail gem</a> will automatically guess the
383
+ mime_type, set the encoding and create the attachment.</p>
384
+ <div class="code_container">
385
+ <pre class="brush: ruby; gutter: false; toolbar: false">
386
+ attachments['filename.jpg'] = File.read('/path/to/filename.jpg')
387
+
388
+ </pre>
389
+ </div>
390
+ </li>
391
+ </ul>
392
+ <p> When the <code>mail</code> method will be triggered, it will send a multipart email with
393
+ an attachment, properly nested with the top level being <code>multipart/mixed</code> and
394
+ the first part being a <code>multipart/alternative</code> containing the plain text and
395
+ HTML email messages.</p><div class="note"><p>Mail will automatically Base64 encode an attachment. If you want something
396
+ different, encode your content and pass in the encoded content and encoding in a
397
+ <code>Hash</code> to the <code>attachments</code> method.</p></div>
398
+ <ul>
399
+ <li>
400
+ <p>Pass the file name and specify headers and content and Action Mailer and Mail
401
+ will use the settings you pass in.</p>
402
+ <div class="code_container">
403
+ <pre class="brush: ruby; gutter: false; toolbar: false">
404
+ encoded_content = SpecialEncode(File.read('/path/to/filename.jpg'))
405
+ attachments['filename.jpg'] = {
406
+ mime_type: 'application/x-gzip',
407
+ encoding: 'SpecialEncoding',
408
+ content: encoded_content
409
+ }
410
+
411
+ </pre>
412
+ </div>
413
+ </li>
414
+ </ul>
415
+ <div class="note"><p>If you specify an encoding, Mail will assume that your content is already
416
+ encoded and not try to Base64 encode it.</p></div><h5 id="making-inline-attachments">2.3.2 Making Inline Attachments</h5><p>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.</p>
417
+ <ul>
418
+ <li>
419
+ <p>First, to tell Mail to turn an attachment into an inline attachment, you just call <code>#inline</code> on the attachments method within your Mailer:</p>
420
+ <div class="code_container">
421
+ <pre class="brush: ruby; gutter: false; toolbar: false">
422
+ def welcome
423
+ attachments.inline['image.jpg'] = File.read('/path/to/image.jpg')
424
+ end
425
+
426
+ </pre>
427
+ </div>
428
+ </li>
429
+ <li>
430
+ <p>Then in your view, you can just reference <code>attachments</code> as a hash and specify
431
+ which attachment you want to show, calling <code>url</code> on it and then passing the
432
+ result into the <code>image_tag</code> method:</p>
433
+ <div class="code_container">
434
+ <pre class="brush: plain; gutter: false; toolbar: false">
435
+ &lt;p&gt;Hello there, this is our image&lt;/p&gt;
436
+
437
+ &lt;%= image_tag attachments['image.jpg'].url %&gt;
438
+
439
+ </pre>
440
+ </div>
441
+ </li>
442
+ <li>
443
+ <p>As this is a standard call to <code>image_tag</code> you can pass in an options hash
444
+ after the attachment URL as you could for any other image:</p>
445
+ <div class="code_container">
446
+ <pre class="brush: plain; gutter: false; toolbar: false">
447
+ &lt;p&gt;Hello there, this is our image&lt;/p&gt;
448
+
449
+ &lt;%= image_tag attachments['image.jpg'].url, alt: 'My Photo',
450
+ class: 'photos' %&gt;
451
+
452
+ </pre>
453
+ </div>
454
+ </li>
455
+ </ul>
456
+ <h5 id="sending-email-to-multiple-recipients">2.3.3 Sending Email To Multiple Recipients</h5><p>It is possible to send email to one or more recipients in one email (e.g.,
457
+ informing all admins of a new signup) by setting the list of emails to the <code>:to</code>
458
+ key. The list of emails can be an array of email addresses or a single string
459
+ with the addresses separated by commas.</p><div class="code_container">
460
+ <pre class="brush: ruby; gutter: false; toolbar: false">
461
+ class AdminMailer &lt; ActionMailer::Base
462
+ default to: Proc.new { Admin.pluck(:email) },
463
+ from: 'notification@example.com'
464
+
465
+ def new_registration(user)
466
+ @user = user
467
+ mail(subject: "New User Signup: #{@user.email}")
468
+ end
469
+ end
470
+
471
+ </pre>
472
+ </div>
473
+ <p>The same format can be used to set carbon copy (Cc:) and blind carbon copy
474
+ (Bcc:) recipients, by using the <code>:cc</code> and <code>:bcc</code> keys respectively.</p><h5 id="sending-email-with-name">2.3.4 Sending Email With Name</h5><p>Sometimes you wish to show the name of the person instead of just their email
475
+ address when they receive the email. The trick to doing that is to format the
476
+ email address in the format <code>"Full Name &lt;email&gt;"</code>.</p><div class="code_container">
477
+ <pre class="brush: ruby; gutter: false; toolbar: false">
478
+ def welcome_email(user)
479
+ @user = user
480
+ email_with_name = %("#{@user.name}" &lt;#{@user.email}&gt;)
481
+ mail(to: email_with_name, subject: 'Welcome to My Awesome Site')
482
+ end
483
+
484
+ </pre>
485
+ </div>
486
+ <h4 id="mailer-views">2.4 Mailer Views</h4><p>Mailer views are located in the <code>app/views/name_of_mailer_class</code> directory. The
487
+ specific mailer view is known to the class because its name is the same as the
488
+ mailer method. In our example from above, our mailer view for the
489
+ <code>welcome_email</code> method will be in <code>app/views/user_mailer/welcome_email.html.erb</code>
490
+ for the HTML version and <code>welcome_email.text.erb</code> for the plain text version.</p><p>To change the default mailer view for your action you do something like:</p><div class="code_container">
491
+ <pre class="brush: ruby; gutter: false; toolbar: false">
492
+ class UserMailer &lt; ActionMailer::Base
493
+ default from: 'notifications@example.com'
494
+
495
+ def welcome_email(user)
496
+ @user = user
497
+ @url = 'http://example.com/login'
498
+ mail(to: @user.email,
499
+ subject: 'Welcome to My Awesome Site',
500
+ template_path: 'notifications',
501
+ template_name: 'another')
502
+ end
503
+ end
504
+
505
+ </pre>
506
+ </div>
507
+ <p>In this case it will look for templates at <code>app/views/notifications</code> with name
508
+ <code>another</code>. You can also specify an array of paths for <code>template_path</code>, and they
509
+ will be searched in order.</p><p>If you want more flexibility you can also pass a block and render specific
510
+ templates or even render inline or text without using a template file:</p><div class="code_container">
511
+ <pre class="brush: ruby; gutter: false; toolbar: false">
512
+ class UserMailer &lt; ActionMailer::Base
513
+ default from: 'notifications@example.com'
514
+
515
+ def welcome_email(user)
516
+ @user = user
517
+ @url = 'http://example.com/login'
518
+ mail(to: @user.email,
519
+ subject: 'Welcome to My Awesome Site') do |format|
520
+ format.html { render 'another_template' }
521
+ format.text { render text: 'Render text' }
522
+ end
523
+ end
524
+ end
525
+
526
+ </pre>
527
+ </div>
528
+ <p>This will render the template 'another_template.html.erb' for the HTML part and
529
+ use the rendered text for the text part. The render command is the same one used
530
+ inside of Action Controller, so you can use all the same options, such as
531
+ <code>:text</code>, <code>:inline</code> etc.</p><h4 id="action-mailer-layouts">2.5 Action Mailer Layouts</h4><p>Just like controller views, you can also have mailer layouts. The layout name
532
+ needs to be the same as your mailer, such as <code>user_mailer.html.erb</code> and
533
+ <code>user_mailer.text.erb</code> to be automatically recognized by your mailer as a
534
+ layout.</p><p>In order to use a different file, call <code>layout</code> in your mailer:</p><div class="code_container">
535
+ <pre class="brush: ruby; gutter: false; toolbar: false">
536
+ class UserMailer &lt; ActionMailer::Base
537
+ layout 'awesome' # use awesome.(html|text).erb as the layout
538
+ end
539
+
540
+ </pre>
541
+ </div>
542
+ <p>Just like with controller views, use <code>yield</code> to render the view inside the
543
+ layout.</p><p>You can also pass in a <code>layout: 'layout_name'</code> option to the render call inside
544
+ the format block to specify different layouts for different formats:</p><div class="code_container">
545
+ <pre class="brush: ruby; gutter: false; toolbar: false">
546
+ class UserMailer &lt; ActionMailer::Base
547
+ def welcome_email(user)
548
+ mail(to: user.email) do |format|
549
+ format.html { render layout: 'my_layout' }
550
+ format.text
551
+ end
552
+ end
553
+ end
554
+
555
+ </pre>
556
+ </div>
557
+ <p>Will render the HTML part using the <code>my_layout.html.erb</code> file and the text part
558
+ with the usual <code>user_mailer.text.erb</code> file if it exists.</p><h4 id="generating-urls-in-action-mailer-views">2.6 Generating URLs in Action Mailer Views</h4><p>Unlike controllers, the mailer instance doesn't have any context about the
559
+ incoming request so you'll need to provide the <code>:host</code> parameter yourself.</p><p>As the <code>:host</code> usually is consistent across the application you can configure it
560
+ globally in <code>config/application.rb</code>:</p><div class="code_container">
561
+ <pre class="brush: ruby; gutter: false; toolbar: false">
562
+ config.action_mailer.default_url_options = { host: 'example.com' }
563
+
564
+ </pre>
565
+ </div>
566
+ <p>Because of this behavior you cannot use any of the <code>*_path</code> helpers inside of
567
+ an email. Instead you will need to use the associated <code>*_url</code> helper. For example
568
+ instead of using</p><div class="code_container">
569
+ <pre class="brush: plain; gutter: false; toolbar: false">
570
+ &lt;%= link_to 'welcome', welcome_path %&gt;
571
+
572
+ </pre>
573
+ </div>
574
+ <p>You will need to use:</p><div class="code_container">
575
+ <pre class="brush: plain; gutter: false; toolbar: false">
576
+ &lt;%= link_to 'welcome', welcome_url %&gt;
577
+
578
+ </pre>
579
+ </div>
580
+ <p>By using the full URL, your links will now work in your emails.</p><h5 id="generating-urls-with-url_for">2.6.1 generating URLs with <code>url_for</code>
581
+ </h5><p>You need to pass the <code>only_path: false</code> option when using <code>url_for</code>. This will
582
+ ensure that absolute URLs are generated because the <code>url_for</code> view helper will,
583
+ by default, generate relative URLs when a <code>:host</code> option isn't explicitly
584
+ provided.</p><div class="code_container">
585
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
586
+ &lt;%= url_for(controller: 'welcome',
587
+ action: 'greeting',
588
+ only_path: false) %&gt;
589
+
590
+ </pre>
591
+ </div>
592
+ <p>If you did not configure the <code>:host</code> option globally make sure to pass it to
593
+ <code>url_for</code>.</p><div class="code_container">
594
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
595
+ &lt;%= url_for(host: 'example.com',
596
+ controller: 'welcome',
597
+ action: 'greeting') %&gt;
598
+
599
+ </pre>
600
+ </div>
601
+ <div class="note"><p>When you explicitly pass the <code>:host</code> Rails will always generate absolute
602
+ URLs, so there is no need to pass <code>only_path: false</code>.</p></div><h5 id="generating-urls-with-named-routes">2.6.2 generating URLs with named routes</h5><p>Email clients have no web context and so paths have no base URL to form complete
603
+ web addresses. Thus, you should always use the "_url" variant of named route
604
+ helpers.</p><p>If you did not configure the <code>:host</code> option globally make sure to pass it to the
605
+ url helper.</p><div class="code_container">
606
+ <pre class="brush: ruby; html-script: true; gutter: false; toolbar: false">
607
+ &lt;%= user_url(@user, host: 'example.com') %&gt;
608
+
609
+ </pre>
610
+ </div>
611
+ <h4 id="sending-multipart-emails">2.7 Sending Multipart Emails</h4><p>Action Mailer will automatically send multipart emails if you have different
612
+ templates for the same action. So, for our UserMailer example, if you have
613
+ <code>welcome_email.text.erb</code> and <code>welcome_email.html.erb</code> in
614
+ <code>app/views/user_mailer</code>, Action Mailer will automatically send a multipart email
615
+ with the HTML and text versions setup as different parts.</p><p>The order of the parts getting inserted is determined by the <code>:parts_order</code>
616
+ inside of the <code>ActionMailer::Base.default</code> method.</p><h4 id="sending-emails-with-dynamic-delivery-options">2.8 Sending Emails with Dynamic Delivery Options</h4><p>If you wish to override the default delivery options (e.g. SMTP credentials)
617
+ while delivering emails, you can do this using <code>delivery_method_options</code> in the
618
+ mailer action.</p><div class="code_container">
619
+ <pre class="brush: ruby; gutter: false; toolbar: false">
620
+ class UserMailer &lt; ActionMailer::Base
621
+ def welcome_email(user, company)
622
+ @user = user
623
+ @url = user_url(@user)
624
+ delivery_options = { user_name: company.smtp_user,
625
+ password: company.smtp_password,
626
+ address: company.smtp_host }
627
+ mail(to: @user.email,
628
+ subject: "Please see the Terms and Conditions attached",
629
+ delivery_method_options: delivery_options)
630
+ end
631
+ end
632
+
633
+ </pre>
634
+ </div>
635
+ <h4 id="sending-emails-without-template-rendering">2.9 Sending Emails without Template Rendering</h4><p>There may be cases in which you want to skip the template rendering step and
636
+ supply the email body as a string. You can achieve this using the <code>:body</code>
637
+ option. In such cases don't forget to add the <code>:content_type</code> option. Rails
638
+ will default to <code>text/plain</code> otherwise.</p><div class="code_container">
639
+ <pre class="brush: ruby; gutter: false; toolbar: false">
640
+ class UserMailer &lt; ActionMailer::Base
641
+ def welcome_email(user, email_body)
642
+ mail(to: user.email,
643
+ body: email_body,
644
+ content_type: "text/html",
645
+ subject: "Already rendered!")
646
+ end
647
+ end
648
+
649
+ </pre>
650
+ </div>
651
+ <h3 id="receiving-emails">3 Receiving Emails</h3><p>Receiving and parsing emails with Action Mailer can be a rather complex
652
+ endeavor. Before your email reaches your Rails app, you would have had to
653
+ configure your system to somehow forward emails to your app, which needs to be
654
+ listening for that. So, to receive emails in your Rails app you'll need to:</p>
655
+ <ul>
656
+ <li><p>Implement a <code>receive</code> method in your mailer.</p></li>
657
+ <li><p>Configure your email server to forward emails from the address(es) you would
658
+ like your app to receive to <code>/path/to/app/bin/rails runner
659
+ 'UserMailer.receive(STDIN.read)'</code>.</p></li>
660
+ </ul>
661
+ <p>Once a method called <code>receive</code> is defined in any mailer, Action Mailer will
662
+ parse the raw incoming email into an email object, decode it, instantiate a new
663
+ mailer, and pass the email object to the mailer <code>receive</code> instance
664
+ method. Here's an example:</p><div class="code_container">
665
+ <pre class="brush: ruby; gutter: false; toolbar: false">
666
+ class UserMailer &lt; ActionMailer::Base
667
+ def receive(email)
668
+ page = Page.find_by(address: email.to.first)
669
+ page.emails.create(
670
+ subject: email.subject,
671
+ body: email.body
672
+ )
673
+
674
+ if email.has_attachments?
675
+ email.attachments.each do |attachment|
676
+ page.attachments.create({
677
+ file: attachment,
678
+ description: email.subject
679
+ })
680
+ end
681
+ end
682
+ end
683
+ end
684
+
685
+ </pre>
686
+ </div>
687
+ <h3 id="action-mailer-callbacks">4 Action Mailer Callbacks</h3><p>Action Mailer allows for you to specify a <code>before_action</code>, <code>after_action</code> and
688
+ <code>around_action</code>.</p>
689
+ <ul>
690
+ <li><p>Filters can be specified with a block or a symbol to a method in the mailer
691
+ class similar to controllers.</p></li>
692
+ <li><p>You could use a <code>before_action</code> to populate the mail object with defaults,
693
+ delivery_method_options or insert default headers and attachments.</p></li>
694
+ <li><p>You could use an <code>after_action</code> to do similar setup as a <code>before_action</code> but
695
+ using instance variables set in your mailer action.</p></li>
696
+ </ul>
697
+ <div class="code_container">
698
+ <pre class="brush: ruby; gutter: false; toolbar: false">
699
+ class UserMailer &lt; ActionMailer::Base
700
+ after_action :set_delivery_options,
701
+ :prevent_delivery_to_guests,
702
+ :set_business_headers
703
+
704
+ def feedback_message(business, user)
705
+ @business = business
706
+ @user = user
707
+ mail
708
+ end
709
+
710
+ def campaign_message(business, user)
711
+ @business = business
712
+ @user = user
713
+ end
714
+
715
+ private
716
+
717
+ def set_delivery_options
718
+ # You have access to the mail instance,
719
+ # @business and @user instance variables here
720
+ if @business &amp;&amp; @business.has_smtp_settings?
721
+ mail.delivery_method.settings.merge!(@business.smtp_settings)
722
+ end
723
+ end
724
+
725
+ def prevent_delivery_to_guests
726
+ if @user &amp;&amp; @user.guest?
727
+ mail.perform_deliveries = false
728
+ end
729
+ end
730
+
731
+ def set_business_headers
732
+ if @business
733
+ headers["X-SMTPAPI-CATEGORY"] = @business.code
734
+ end
735
+ end
736
+ end
737
+
738
+ </pre>
739
+ </div>
740
+
741
+ <ul>
742
+ <li>Mailer Filters abort further processing if body is set to a non-nil value.</li>
743
+ </ul>
744
+ <h3 id="using-action-mailer-helpers">5 Using Action Mailer Helpers</h3><p>Action Mailer now just inherits from <code>AbstractController</code>, so you have access to
745
+ the same generic helpers as you do in Action Controller.</p><h3 id="action-mailer-configuration">6 Action Mailer Configuration</h3><p>The following configuration options are best made in one of the environment
746
+ files (environment.rb, production.rb, etc...)</p>
747
+ <table>
748
+ <thead>
749
+ <tr>
750
+ <th>Configuration</th>
751
+ <th>Description</th>
752
+ </tr>
753
+ </thead>
754
+ <tbody>
755
+ <tr>
756
+ <td><code>logger</code></td>
757
+ <td>Generates information on the mailing run if available. Can be set to <code>nil</code> for no logging. Compatible with both Ruby's own <code>Logger</code> and <code>Log4r</code> loggers.</td>
758
+ </tr>
759
+ <tr>
760
+ <td><code>smtp_settings</code></td>
761
+ <td>Allows detailed configuration for <code>:smtp</code> delivery method:<ul>
762
+ <li>
763
+ <code>:address</code> - Allows you to use a remote mail server. Just change it from its default <code>"localhost"</code> setting.</li>
764
+ <li>
765
+ <code>:port</code> - On the off chance that your mail server doesn't run on port 25, you can change it.</li>
766
+ <li>
767
+ <code>:domain</code> - If you need to specify a HELO domain, you can do it here.</li>
768
+ <li>
769
+ <code>:user_name</code> - If your mail server requires authentication, set the username in this setting.</li>
770
+ <li>
771
+ <code>:password</code> - If your mail server requires authentication, set the password in this setting.</li>
772
+ <li>
773
+ <code>:authentication</code> - If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of <code>:plain</code>, <code>:login</code>, <code>:cram_md5</code>.</li>
774
+ <li>
775
+ <code>:enable_starttls_auto</code> - Set this to <code>false</code> if there is a problem with your server certificate that you cannot resolve.</li>
776
+ </ul>
777
+ </td>
778
+ </tr>
779
+ <tr>
780
+ <td><code>sendmail_settings</code></td>
781
+ <td>Allows you to override options for the <code>:sendmail</code> delivery method.<ul>
782
+ <li>
783
+ <code>:location</code> - The location of the sendmail executable. Defaults to <code>/usr/sbin/sendmail</code>.</li>
784
+ <li>
785
+ <code>:arguments</code> - The command line arguments to be passed to sendmail. Defaults to <code>-i -t</code>.</li>
786
+ </ul>
787
+ </td>
788
+ </tr>
789
+ <tr>
790
+ <td><code>raise_delivery_errors</code></td>
791
+ <td>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.</td>
792
+ </tr>
793
+ <tr>
794
+ <td><code>delivery_method</code></td>
795
+ <td>Defines a delivery method. Possible values are:<ul>
796
+ <li>
797
+ <code>:smtp</code> (default), can be configured by using <code>config.action_mailer.smtp_settings</code>.</li>
798
+ <li>
799
+ <code>:sendmail</code>, can be configured by using <code>config.action_mailer.sendmail_settings</code>.</li>
800
+ <li>
801
+ <code>:file</code>: save emails to files; can be configured by using <code>config.action_mailer.file_settings</code>.</li>
802
+ <li>
803
+ <code>:test</code>: save emails to <code>ActionMailer::Base.deliveries</code> array.</li>
804
+ </ul>See <a href="http://api.rubyonrails.org/classes/ActionMailer/Base.html">API docs</a> for more info.</td>
805
+ </tr>
806
+ <tr>
807
+ <td><code>perform_deliveries</code></td>
808
+ <td>Determines whether deliveries are actually carried out when the <code>deliver</code> method is invoked on the Mail message. By default they are, but this can be turned off to help functional testing.</td>
809
+ </tr>
810
+ <tr>
811
+ <td><code>deliveries</code></td>
812
+ <td>Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test. Most useful for unit and functional testing.</td>
813
+ </tr>
814
+ <tr>
815
+ <td><code>default_options</code></td>
816
+ <td>Allows you to set default values for the <code>mail</code> method options (<code>:from</code>, <code>:reply_to</code>, etc.).</td>
817
+ </tr>
818
+ </tbody>
819
+ </table>
820
+ <p>For a complete writeup of possible configurations see the
821
+ <a href="configuring.html#configuring-action-mailer">Configuring Action Mailer</a> in
822
+ our Configuring Rails Applications guide.</p><h4 id="example-action-mailer-configuration">6.1 Example Action Mailer Configuration</h4><p>An example would be adding the following to your appropriate
823
+ <code>config/environments/$RAILS_ENV.rb</code> file:</p><div class="code_container">
824
+ <pre class="brush: ruby; gutter: false; toolbar: false">
825
+ config.action_mailer.delivery_method = :sendmail
826
+ # Defaults to:
827
+ # config.action_mailer.sendmail_settings = {
828
+ # location: '/usr/sbin/sendmail',
829
+ # arguments: '-i -t'
830
+ # }
831
+ config.action_mailer.perform_deliveries = true
832
+ config.action_mailer.raise_delivery_errors = true
833
+ config.action_mailer.default_options = {from: 'no-reply@example.com'}
834
+
835
+ </pre>
836
+ </div>
837
+ <h4 id="action-mailer-configuration-for-gmail">6.2 Action Mailer Configuration for Gmail</h4><p>As Action Mailer now uses the <a href="https://github.com/mikel/mail">Mail gem</a>, this
838
+ becomes as simple as adding to your <code>config/environments/$RAILS_ENV.rb</code> file:</p><div class="code_container">
839
+ <pre class="brush: ruby; gutter: false; toolbar: false">
840
+ config.action_mailer.delivery_method = :smtp
841
+ config.action_mailer.smtp_settings = {
842
+ address: 'smtp.gmail.com',
843
+ port: 587,
844
+ domain: 'example.com',
845
+ user_name: '&lt;username&gt;',
846
+ password: '&lt;password&gt;',
847
+ authentication: 'plain',
848
+ enable_starttls_auto: true }
849
+
850
+ </pre>
851
+ </div>
852
+ <h3 id="mailer-testing">7 Mailer Testing</h3><p>You can find detailed instructions on how to test your mailers in the
853
+ <a href="testing.html#testing-your-mailers">testing guide</a>.</p><h3 id="intercepting-emails">8 Intercepting Emails</h3><p>There are situations where you need to edit an email before it's
854
+ delivered. Fortunately Action Mailer provides hooks to intercept every
855
+ email. You can register an interceptor to make modifications to mail messages
856
+ right before they are handed to the delivery agents.</p><div class="code_container">
857
+ <pre class="brush: ruby; gutter: false; toolbar: false">
858
+ class SandboxEmailInterceptor
859
+ def self.delivering_email(message)
860
+ message.to = ['sandbox@example.com']
861
+ end
862
+ end
863
+
864
+ </pre>
865
+ </div>
866
+ <p>Before the interceptor can do its job you need to register it with the Action
867
+ Mailer framework. You can do this in an initializer file
868
+ <code>config/initializers/sandbox_email_interceptor.rb</code></p><div class="code_container">
869
+ <pre class="brush: ruby; gutter: false; toolbar: false">
870
+ ActionMailer::Base.register_interceptor(SandboxEmailInterceptor) if Rails.env.staging?
871
+
872
+ </pre>
873
+ </div>
874
+ <div class="note"><p>The example above uses a custom environment called "staging" for a
875
+ production like server but for testing purposes. You can read
876
+ <a href="configuring.html#creating-rails-environments">Creating Rails environments</a>
877
+ for more information about custom Rails environments.</p></div>
878
+
879
+ <h3>Feedback</h3>
880
+ <p>
881
+ You're encouraged to help improve the quality of this guide.
882
+ </p>
883
+ <p>
884
+ Please contribute if you see any typos or factual errors.
885
+ To get started, you can read our <a href="http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#contributing-to-the-rails-documentation">documentation contributions</a> section.
886
+ </p>
887
+ <p>
888
+ You may also find incomplete content, or stuff that is not up to date.
889
+ Please do add any missing documentation for master. Make sure to check
890
+ <a href="http://edgeguides.rubyonrails.org">Edge Guides</a> first to verify
891
+ if the issues are already fixed or not on the master branch.
892
+ Check the <a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a>
893
+ for style and conventions.
894
+ </p>
895
+ <p>
896
+ If for whatever reason you spot something to fix but cannot patch it yourself, please
897
+ <a href="https://github.com/rails/rails/issues">open an issue</a>.
898
+ </p>
899
+ <p>And last but not least, any kind of discussion regarding Ruby on Rails
900
+ documentation is very welcome in the <a href="http://groups.google.com/group/rubyonrails-docs">rubyonrails-docs mailing list</a>.
901
+ </p>
902
+ </div>
903
+ </div>
904
+ </div>
905
+
906
+ <hr class="hide" />
907
+ <div id="footer">
908
+ <div class="wrapper">
909
+ <p>This work is licensed under a <a href="https://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International</a> License</p>
910
+ <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p>
911
+
912
+ </div>
913
+ </div>
914
+
915
+ <script type="text/javascript" src="javascripts/jquery.min.js"></script>
916
+ <script type="text/javascript" src="javascripts/responsive-tables.js"></script>
917
+ <script type="text/javascript" src="javascripts/guides.js"></script>
918
+ <script type="text/javascript" src="javascripts/syntaxhighlighter/shCore.js"></script>
919
+ <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushRuby.js"></script>
920
+ <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushXml.js"></script>
921
+ <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushSql.js"></script>
922
+ <script type="text/javascript" src="javascripts/syntaxhighlighter/shBrushPlain.js"></script>
923
+ <script type="text/javascript">
924
+ SyntaxHighlighter.all();
925
+ $(guidesIndex.bind);
926
+ </script>
927
+ </body>
928
+ </html>