From 3762362eab9663b3c9bc6d4b831e402917f95e93 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Mon, 7 Jun 2010 23:14:54 -0400 Subject: Updating readme for ActionMailer::Base --- actionmailer/lib/action_mailer/base.rb | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'actionmailer') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 9fb3ba425f..7da033b6af 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -36,6 +36,9 @@ module ActionMailer #:nodoc: # * attachments[]= - Allows you to add attachments to your email in an intuitive # manner; attachments['filename.png'] = File.read('path/to/filename.png') # + # * attachments.inline[]= - Allows you to add an inline attachment to your email + # in the same manner as attachments[]= + # # * headers[]= - Allows you to specify any header field in your email such # as headers['X-No-Spam'] = 'True'. Note, while most fields (like To: # From: can only appear once in an email header, other fields like X-Anything @@ -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 application/pdf 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 welcome.html.erb 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: + # + #

Please Don't Cringe

+ # + # <%= image_tag attachments['photo.png'].url -%> + # + # As we are using ActionView's +image_tag+ method, you can pass in any other options you want: + # + #

Please Don't Cringe

+ # + # <%= 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 -- cgit v1.2.3