aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source
diff options
context:
space:
mode:
authorMichael Erb <michael@erbmicha.com>2009-03-06 16:27:52 -0500
committerMichael Erb <michael@erbmicha.com>2009-03-06 16:27:52 -0500
commit06cbc3dc90c9d2e9d1becce4dfc5be62b0abedaa (patch)
tree148059ba3c998940cde91a8032a90c7ad579e82c /railties/guides/source
parentda242d4d0976835d3ae4319910e8c8239c3cb2e5 (diff)
downloadrails-06cbc3dc90c9d2e9d1becce4dfc5be62b0abedaa.tar.gz
rails-06cbc3dc90c9d2e9d1becce4dfc5be62b0abedaa.tar.bz2
rails-06cbc3dc90c9d2e9d1becce4dfc5be62b0abedaa.zip
added 'Sending multipart emails with attachments' section for ActionMailer guide
Diffstat (limited to 'railties/guides/source')
-rw-r--r--railties/guides/source/action_mailer_basics.textile32
1 files changed, 32 insertions, 0 deletions
diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile
index 71398382be..0e52bf6f32 100644
--- a/railties/guides/source/action_mailer_basics.textile
+++ b/railties/guides/source/action_mailer_basics.textile
@@ -262,6 +262,38 @@ class UserMailer < ActionMailer::Base
end
</ruby>
+h4. Sending multipart emails with attachments
+
+Once you use the +attachment+ method, ActionMailer will no longer automagically use the correct template based on the filename. You must declare which template you are using for each content type via the +part+ method.
+
+In the following example, there would be two template files, +welcome_email_html.erb+ and +welcome_email_plain.erb+ in the +app/views/user_mailer+ folder.
+
+<ruby>
+class UserMailer < ActionMailer::Base
+ def welcome_email(user)
+ recipients user.email_address
+ subject "New account information"
+ from "system@example.com"
+ content_type "multipart/alternative"
+
+ part "text/html" do |p|
+ p.body = render_message("welcome_email_html", :message => "<h1>HTML content</h1>")
+ end
+
+ part "text/plain" do |p|
+ p.body = render_message("welcome_email_plain", :message => "text content")
+ end
+
+ attachment :content_type => "image/jpeg",
+ :body => File.read("an-image.jpg")
+
+ attachment "application/pdf" do |a|
+ a.body = generate_your_pdf_here()
+ end
+ end
+end
+</ruby>
+
h3. Receiving Emails
Receiving and parsing emails with Action Mailer can be a rather complex endeavour. Before your email reaches your Rails app, you would have had to configure your system to somehow forward emails to your app, which needs to be listening for that. So, to receive emails in your Rails app you'll need: