diff options
Diffstat (limited to 'actionmailer/lib')
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 19 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/railtie.rb | 3 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/railties/subscriber.rb | 20 |
3 files changed, 31 insertions, 11 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 597260ab0b..13c9fbd516 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -399,9 +399,10 @@ module ActionMailer #:nodoc: # end # end def receive(raw_email) - logger.info "Received mail:\n #{raw_email}" unless logger.nil? mail = Mail.new(raw_email) - new.receive(mail) + ActiveSupport::Notifications.instrument("action_mailer.receive", :mail => mail) do + new.receive(mail) + end end # Deliver the given mail object directly. This can be used to deliver @@ -494,17 +495,13 @@ module ActionMailer #:nodoc: def deliver!(mail = @mail) raise "no mail object available for delivery!" unless mail - if logger - logger.info "Sent mail to #{Array(recipients).join(', ')}" - logger.debug "\n#{mail.encoded}" - end - - ActiveSupport::Notifications.instrument("action_mailer.deliver", :mail => self) do - begin + begin + ActiveSupport::Notifications.instrument("action_mailer.deliver", + :mail => @mail, :mailer => self) do self.delivery_method.perform_delivery(mail) if perform_deliveries - rescue Exception => e # Net::SMTP errors or sendmail pipe errors - raise e if raise_delivery_errors end + rescue Exception => e # Net::SMTP errors or sendmail pipe errors + raise e if raise_delivery_errors end mail diff --git a/actionmailer/lib/action_mailer/railtie.rb b/actionmailer/lib/action_mailer/railtie.rb index 5410c7d75f..b05d21ae5d 100644 --- a/actionmailer/lib/action_mailer/railtie.rb +++ b/actionmailer/lib/action_mailer/railtie.rb @@ -5,6 +5,9 @@ module ActionMailer class Railtie < Rails::Railtie plugin_name :action_mailer + require "action_mailer/railties/subscriber" + subscriber ActionMailer::Railties::Subscriber.new + initializer "action_mailer.set_configs" do |app| app.config.action_mailer.each do |k,v| ActionMailer::Base.send "#{k}=", v diff --git a/actionmailer/lib/action_mailer/railties/subscriber.rb b/actionmailer/lib/action_mailer/railties/subscriber.rb new file mode 100644 index 0000000000..aafc155b09 --- /dev/null +++ b/actionmailer/lib/action_mailer/railties/subscriber.rb @@ -0,0 +1,20 @@ +module ActionMailer + module Railties + class Subscriber < Rails::Subscriber + def deliver(event) + recipients = Array(event.payload[:mailer].recipients).join(', ') + info("Sent mail to #{recipients} (%1.fms)" % event.duration) + debug("\n#{event.payload[:mail].encoded}") + end + + def receive(event) + info("Received mail (%.1fms)" % event.duration) + debug("\n#{event.payload[:mail].encoded}") + end + + def logger + ActionMailer::Base.logger + end + end + end +end
\ No newline at end of file |