diff options
author | Xavier Noria <fxn@hashref.com> | 2010-06-08 21:23:29 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-06-08 21:23:29 +0200 |
commit | 751f79a03351f1f0d21436b2b947352b97ded093 (patch) | |
tree | 9dd053597389241398c9173ab7f565697bef055f /actionmailer/lib | |
parent | e7e6ee3e7b075f5447697a6038cb46d65f9b137a (diff) | |
parent | ab2877cbe89e266ee986fc12e603abd93ac017ad (diff) | |
download | rails-751f79a03351f1f0d21436b2b947352b97ded093.tar.gz rails-751f79a03351f1f0d21436b2b947352b97ded093.tar.bz2 rails-751f79a03351f1f0d21436b2b947352b97ded093.zip |
Merge remote branch 'rails/master'
Diffstat (limited to 'actionmailer/lib')
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 39 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/mail_helper.rb | 5 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/version.rb | 2 |
3 files changed, 43 insertions, 3 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 3a82979d35..7da033b6af 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -36,6 +36,9 @@ module ActionMailer #:nodoc: # * <tt>attachments[]=</tt> - Allows you to add attachments to your email in an intuitive # manner; <tt>attachments['filename.png'] = File.read('path/to/filename.png')</tt> # + # * <tt>attachments.inline[]=</tt> - Allows you to add an inline attachment to your email + # in the same manner as <tt>attachments[]=</tt> + # # * <tt>headers[]=</tt> - Allows you to specify any header field in your email such # as <tt>headers['X-No-Spam'] = 'True'</tt>. Note, while most fields (like <tt>To:</tt> # <tt>From:</tt> can only appear once in an email header, other fields like <tt>X-Anything</tt> @@ -173,7 +176,7 @@ module ActionMailer #:nodoc: # # class ApplicationMailer < ActionMailer::Base # def welcome(recipient) - # attachments['free_book.pdf'] = { :data => File.read('path/to/file.pdf') } + # attachments['free_book.pdf'] = File.read('path/to/file.pdf') # mail(:to => recipient, :subject => "New account information") # end # end @@ -184,6 +187,34 @@ module ActionMailer #:nodoc: # and the second being a <tt>application/pdf</tt> with a Base64 encoded copy of the file.pdf book # with the filename +free_book.pdf+. # + # = Inline Attachments + # + # You can also specify that a file should be displayed inline with other HTML. For example a + # corporate logo or a photo or the like. + # + # To do this is simple, in the Mailer: + # + # class ApplicationMailer < ActionMailer::Base + # def welcome(recipient) + # attachments.inline['photo.png'] = File.read('path/to/photo.png') + # mail(:to => recipient, :subject => "Here is what we look like") + # end + # end + # + # And then to reference the image in the view, you create a <tt>welcome.html.erb</tt> file and + # make a call to +image_tag+ passing in the attachment you want to display and then call + # +url+ on the attachment to get the relative content id path for the image source: + # + # <h1>Please Don't Cringe</h1> + # + # <%= image_tag attachments['photo.png'].url -%> + # + # As we are using ActionView's +image_tag+ method, you can pass in any other options you want: + # + # <h1>Please Don't Cringe</h1> + # + # <%= image_tag attachments['photo.png'].url, :alt => 'Our Photo', :class => 'photo' -%> + # # = Observing and Intercepting Mails # # Action Mailer provides hooks into the Mail observer and interceptor methods. These allow you to @@ -612,7 +643,11 @@ module ActionMailer #:nodoc: when user_content_type.present? user_content_type when m.has_attachments? - ["multipart", "mixed", params] + if m.attachments.detect { |a| a.inline? } + ["multipart", "related", params] + else + ["multipart", "mixed", params] + end when m.multipart? ["multipart", "alternative", params] else diff --git a/actionmailer/lib/action_mailer/mail_helper.rb b/actionmailer/lib/action_mailer/mail_helper.rb index aab6e12387..b708881edf 100644 --- a/actionmailer/lib/action_mailer/mail_helper.rb +++ b/actionmailer/lib/action_mailer/mail_helper.rb @@ -32,5 +32,10 @@ module ActionMailer def message @_message end + + # Access the message attachments list. + def attachments + @_message.attachments + end end end diff --git a/actionmailer/lib/action_mailer/version.rb b/actionmailer/lib/action_mailer/version.rb index e66172c8d3..8c19082f61 100644 --- a/actionmailer/lib/action_mailer/version.rb +++ b/actionmailer/lib/action_mailer/version.rb @@ -3,7 +3,7 @@ module ActionMailer MAJOR = 3 MINOR = 0 TINY = 0 - BUILD = "beta3" + BUILD = "beta4" STRING = [MAJOR, MINOR, TINY, BUILD].join('.') end |