From 23aa94a7b2d51536baa5eb91a8cd50cdd6dfa99e Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Mon, 2 Dec 2013 16:51:13 +0100 Subject: `mail()` without arguments is a getter for the current mail. This behavior is documented in our guides (http://edgeguides.rubyonrails.org/action_mailer_basics.html#action-mailer-callbacks) but was broken in the past. This commit short curcuits the `mail` method if: 1. mail() was previously called 2. no headers are passed 3. no block is passed Closes #13090. /cc @pixeltrix --- actionmailer/lib/action_mailer/base.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionmailer/lib/action_mailer/base.rb') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 501fee55aa..6f8ae05539 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -689,6 +689,8 @@ module ActionMailer # end # def mail(headers = {}, &block) + return @_message if @_mail_was_called && headers.blank? && !block + @_mail_was_called = true m = @_message -- cgit v1.2.3 From e064658d64f7fb071ec35764f2d5203e8b58e044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Strza=C5=82kowski?= Date: Thu, 5 Dec 2013 00:22:50 +0100 Subject: Include AV::Layouts directly in AM::Base No need to do this in railtie as AM depends on AV either way --- actionmailer/lib/action_mailer/base.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionmailer/lib/action_mailer/base.rb') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 6f8ae05539..5723b2cc1b 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -373,6 +373,8 @@ module ActionMailer include AbstractController::AssetPaths include AbstractController::Callbacks + include ActionView::Layouts + PROTECTED_IVARS = AbstractController::Rendering::DEFAULT_PROTECTED_INSTANCE_VARIABLES + [:@_action_has_layout] def _protected_ivars # :nodoc: -- cgit v1.2.3 From d6dec7fcb6b8fddf8c170182d4fe64ecfc7b2261 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Mon, 16 Dec 2013 05:52:58 +0000 Subject: Add mailer previews feature based on mail_view gem --- actionmailer/lib/action_mailer/base.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'actionmailer/lib/action_mailer/base.rb') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 5723b2cc1b..e1f3fd03e2 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -308,6 +308,25 @@ module ActionMailer # 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. # + # = Previewing emails + # + # You can preview your email templates visually by adding a mailer preview file to the + # ActionMailer::Base.preview_path. Since most emails do something interesting + # with database data, you'll need to write some scenarios to load messages with fake data: + # + # class NotifierPreview < ActionMailer::Preview + # def welcome + # Notifier.welcome(User.first) + # end + # end + # + # Methods must return a Mail::Message object which can be generated by calling the mailer + # method without the additional deliver. The location of the mailer previews + # directory can be configured using the preview_path option which has a default + # of test/mailers/previews: + # + # config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews" + # # = Configuration options # # These options are specified on the class level, like @@ -362,6 +381,7 @@ module ActionMailer # delivery_method :test. Most useful for unit and functional testing. class Base < AbstractController::Base include DeliveryMethods + include Previews abstract! -- cgit v1.2.3 From 69b5dc7e002946c5196a7a38e2559a7ce08a75c0 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Wed, 18 Dec 2013 14:36:31 +0100 Subject: document how to access mail previews. [ci skip] /cc @pixeltrix --- actionmailer/lib/action_mailer/base.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'actionmailer/lib/action_mailer/base.rb') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index e1f3fd03e2..3c21db991c 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -327,6 +327,9 @@ module ActionMailer # # config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews" # + # An overview of all previews is accessible at http://localhost:3000/rails/mailers + # on a running development server instance. + # # = Configuration options # # These options are specified on the class level, like -- cgit v1.2.3 From fbbd4e18994490f00509a5269bbca0dd3521c3ae Mon Sep 17 00:00:00 2001 From: Chun-wei Kuo Date: Thu, 26 Dec 2013 18:14:38 +0800 Subject: Improve font of some code in API documentation [ci skip] * Add "" or "+" to improve font of some code and filenames in API documentation * Does not contain wording changes --- actionmailer/lib/action_mailer/base.rb | 35 +++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'actionmailer/lib/action_mailer/base.rb') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 3c21db991c..275f657f8a 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -50,7 +50,7 @@ module ActionMailer # # * mail - Allows you to specify email to be sent. # - # The hash passed to the mail method allows you to specify any header that a Mail::Message + # The hash passed to the mail method allows you to specify any header that a Mail::Message # will accept (any valid Email header including optional fields). # # The mail method, if not passed a block, will inspect your views and send all the views with @@ -229,7 +229,7 @@ module ActionMailer # An interceptor class must implement the :delivering_email(message) method which will be # called before the email is sent, allowing you to make modifications to the email before it hits # the delivery agents. Your class should make any needed modifications directly to the passed - # in Mail::Message instance. + # in Mail::Message instance. # # = Default Hash # @@ -320,7 +320,7 @@ module ActionMailer # end # end # - # Methods must return a Mail::Message object which can be generated by calling the mailer + # Methods must return a Mail::Message object which can be generated by calling the mailer # method without the additional deliver. The location of the mailer previews # directory can be configured using the preview_path option which has a default # of test/mailers/previews: @@ -339,7 +339,7 @@ module ActionMailer # per the above section. # # * logger - the logger is used for generating information on the mailing run if available. - # Can be set to nil for no logging. Compatible with both Ruby's own Logger and Log4r loggers. + # Can be set to +nil+ for no logging. Compatible with both Ruby's own +Logger+ and Log4r loggers. # # * smtp_settings - Allows detailed configuration for :smtp delivery method: # * :address - Allows you to use a remote mail server. Just change it from its default @@ -357,8 +357,9 @@ module ActionMailer # and starts to use it. # * :openssl_verify_mode - 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 ('none', 'peer', 'client_once', 'fail_if_no_peer_cert') or directly the - # constant (OpenSSL::SSL::VERIFY_NONE, OpenSSL::SSL::VERIFY_PEER, ...). + # of an OpenSSL verify constant ('none', 'peer', 'client_once', + # 'fail_if_no_peer_cert') or directly the constant (OpenSSL::SSL::VERIFY_NONE, + # OpenSSL::SSL::VERIFY_PEER, ...). # # * sendmail_settings - Allows you to override options for the :sendmail delivery method. # * :location - The location of the sendmail executable. Defaults to /usr/sbin/sendmail. @@ -373,7 +374,7 @@ module ActionMailer # # * delivery_method - Defines a delivery method. Possible values are :smtp (default), # :sendmail, :test, and :file. Or you may provide a custom delivery method - # object e.g. MyOwnDeliveryMethodClass. See the Mail gem documentation on the interface you need to + # object e.g. +MyOwnDeliveryMethodClass+. See the Mail gem documentation on the interface you need to # implement for a custom delivery agent. # # * perform_deliveries - Determines whether emails are actually sent from Action Mailer when you @@ -429,7 +430,7 @@ module ActionMailer # Register an Observer which will be notified when mail is delivered. # Either a class or a string can be passed in as the Observer. If a string is passed in - # it will be +constantize+d. + # it will be constantized. def register_observer(observer) delivery_observer = (observer.is_a?(String) ? observer.constantize : observer) Mail.register_observer(delivery_observer) @@ -487,11 +488,11 @@ module ActionMailer end end - # Wraps an email delivery inside of ActiveSupport::Notifications instrumentation. + # Wraps an email delivery inside of ActiveSupport::Notifications instrumentation. # - # This method is actually called by the Mail::Message object itself - # through a callback when you call +:deliver+ on the Mail::Message, - # calling +deliver_mail+ directly and passing a Mail::Message will do + # This method is actually called by the Mail::Message object itself + # through a callback when you call :deliver on the Mail::Message, + # calling +deliver_mail+ directly and passing a Mail::Message will do # nothing except tell the logger you sent the email. def deliver_mail(mail) #:nodoc: ActiveSupport::Notifications.instrument("deliver.action_mailer") do |payload| @@ -567,18 +568,18 @@ module ActionMailer self.class.mailer_name end - # Allows you to pass random and unusual headers to the new Mail::Message + # Allows you to pass random and unusual headers to the new Mail::Message # object which will add them to itself. # # headers['X-Special-Domain-Specific-Header'] = "SecretValue" # # You can also pass a hash into headers of header field names and values, - # which will then be set on the Mail::Message object: + # which will then be set on the Mail::Message object: # # headers 'X-Special-Domain-Specific-Header' => "SecretValue", # 'In-Reply-To' => incoming.message_id # - # The resulting Mail::Message will have the following in its header: + # The resulting Mail::Message will have the following in its header: # # X-Special-Domain-Specific-Header: SecretValue def headers(args = nil) @@ -667,8 +668,8 @@ module ActionMailer # templates in the view paths using by default the mailer name and the # method name that it is being called from, it will then create parts for # each of these templates intelligently, making educated guesses on correct - # content type and sequence, and return a fully prepared Mail::Message - # ready to call +:deliver+ on to send. + # content type and sequence, and return a fully prepared Mail::Message + # ready to call :deliver on to send. # # For example: # -- cgit v1.2.3