lib/action_mailer/base.rb in actionmailer-4.1.16 vs lib/action_mailer/base.rb in actionmailer-4.2.0.beta1

- old
+ new

@@ -92,11 +92,11 @@ # Emails by default are sent in plain text, so a sample view for our model example might look like this: # # Hi <%= @account.name %>, # Thanks for joining our service! Please check back often. # - # You can even use Action Pack helpers in these views. For example: + # You can even use Action View helpers in these views. For example: # # You got a new note! # <%= truncate(@note.body, length: 25) %> # # If you need to access the subject, from or the recipients in the view, you can do that through message object: @@ -152,11 +152,11 @@ # # For example, if the following templates exist: # * signup_notification.text.erb # * signup_notification.html.erb # * signup_notification.xml.builder - # * signup_notification.yaml.erb + # * signup_notification.yml.erb # # Each would be rendered and added as a separate part to the message, with the corresponding content # type. The content type for the entire message is automatically set to <tt>multipart/alternative</tt>, # which indicates that the email contains multiple different representations of the same email # body. The same instance variables defined in the action are passed to all email templates. @@ -299,16 +299,17 @@ # def add_inline_attachment! # attachments.inline["footer.jpg"] = File.read('/path/to/filename.jpg') # end # end # - # Callbacks in ActionMailer are implemented using AbstractController::Callbacks, so you - # can define and configure callbacks in the same manner that you would use callbacks in - # classes that inherit from ActionController::Base. + # Callbacks in Action Mailer are implemented using + # <tt>AbstractController::Callbacks</tt>, so you can define and configure + # callbacks in the same manner that you would use callbacks in classes that + # inherit from <tt>ActionController::Base</tt>. # # Note that unless you have a specific reason to do so, you should prefer using before_action - # rather than after_action in your ActionMailer classes so that headers are parsed properly. + # rather than after_action in your Action Mailer classes so that headers are parsed properly. # # = Previewing emails # # You can preview your email templates visually by adding a mailer preview file to the # <tt>ActionMailer::Base.preview_path</tt>. Since most emails do something interesting @@ -323,11 +324,11 @@ # Methods must return a <tt>Mail::Message</tt> object which can be generated by calling the mailer # method without the additional <tt>deliver</tt>. The location of the mailer previews # directory can be configured using the <tt>preview_path</tt> option which has a default # of <tt>test/mailers/previews</tt>: # - # config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews" + # config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews" # # An overview of all previews is accessible at <tt>http://localhost:3000/rails/mailers</tt> # on a running development server instance. # # Previews can also be intercepted in a similar manner as deliveries can be by registering @@ -366,12 +367,12 @@ # * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the # authentication type here. # This is a symbol and one of <tt>:plain</tt> (will send the password in the clear), <tt>:login</tt> (will # send password Base64 encoded) or <tt>:cram_md5</tt> (combines a Challenge/Response mechanism to exchange # information and a cryptographic Message Digest 5 algorithm to hash important information) - # * <tt>:enable_starttls_auto</tt> - When set to true, detects if STARTTLS is enabled in your SMTP server - # and starts to use it. + # * <tt>:enable_starttls_auto</tt> - Detects if STARTTLS is enabled in your SMTP server and starts + # to use it. Defaults to <tt>true</tt>. # * <tt>:openssl_verify_mode</tt> - When using TLS, you can set how OpenSSL checks the certificate. This is # really useful if you need to validate a self-signed and/or a wildcard certificate. You can use the name # of an OpenSSL verify constant (<tt>'none'</tt>, <tt>'peer'</tt>, <tt>'client_once'</tt>, # <tt>'fail_if_no_peer_cert'</tt>) or directly the constant (<tt>OpenSSL::SSL::VERIFY_NONE</tt>, # <tt>OpenSSL::SSL::VERIFY_PEER</tt>, ...). @@ -391,11 +392,11 @@ # <tt>:sendmail</tt>, <tt>:test</tt>, and <tt>:file</tt>. Or you may provide a custom delivery method # object e.g. +MyOwnDeliveryMethodClass+. See the Mail gem documentation on the interface you need to # implement for a custom delivery agent. # # * <tt>perform_deliveries</tt> - Determines whether emails are actually sent from Action Mailer when you - # call <tt>.deliver</tt> on an mail message or on an Action Mailer method. This is on by default but can + # call <tt>.deliver</tt> on an email message or on an Action Mailer method. This is on by default but can # be turned off to aid in functional testing. # # * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with # <tt>delivery_method :test</tt>. Most useful for unit and functional testing. class Base < AbstractController::Base @@ -545,12 +546,12 @@ payload[:date] = mail.date payload[:mail] = mail.encoded end def method_missing(method_name, *args) # :nodoc: - if respond_to?(method_name) - new(method_name, *args).message + if action_methods.include?(method_name.to_s) + MessageDelivery.new(self, method_name, *args) else super end end end @@ -582,12 +583,15 @@ end end class NullMail #:nodoc: def body; '' end - def header; {} end + def respond_to?(string, include_all=false) + true + end + def method_missing(*args) nil end end @@ -758,10 +762,11 @@ # end # def mail(headers = {}, &block) return @_message if @_mail_was_called && headers.blank? && !block + @_mail_was_called = true m = @_message # At the beginning, do not consider class default for content_type content_type = headers[:content_type] @@ -785,12 +790,10 @@ assignable = headers.except(:parts_order, :content_type, :body, :template_name, :template_path) assignable.each { |k, v| m[k] = v } # Render the templates and blocks responses = collect_responses(headers, &block) - @_mail_was_called = true - create_parts_from_responses(m, responses) # Setup content type, reapply charset and handle parts order m.content_type = set_content_type(m, content_type, headers[:content_type]) m.charset = charset @@ -894,9 +897,14 @@ def insert_part(container, response, charset) #:nodoc: response[:charset] ||= charset part = Mail::Part.new(response) container.add_part(part) + end + + # Emails do not support relative path links. + def self.supports_path? + false end ActiveSupport.run_load_hooks(:action_mailer, self) end end