Log email delivery errors (#14403).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12010 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
6ecd90e7ff
commit
8ff33ac9f7
|
@ -430,7 +430,17 @@ class Mailer < ActionMailer::Base
|
||||||
|
|
||||||
def self.deliver_mail(mail)
|
def self.deliver_mail(mail)
|
||||||
return false if mail.to.blank? && mail.cc.blank? && mail.bcc.blank?
|
return false if mail.to.blank? && mail.cc.blank? && mail.bcc.blank?
|
||||||
super
|
begin
|
||||||
|
# Log errors when raise_delivery_errors is set to false, Rails does not
|
||||||
|
mail.raise_delivery_errors = true
|
||||||
|
super
|
||||||
|
rescue Exception => e
|
||||||
|
if ActionMailer::Base.raise_delivery_errors
|
||||||
|
raise e
|
||||||
|
else
|
||||||
|
Rails.logger.error "Email delivery error: #{e.message}"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.method_missing(method, *args, &block)
|
def self.method_missing(method, *args, &block)
|
||||||
|
|
|
@ -661,6 +661,29 @@ class MailerTest < ActiveSupport::TestCase
|
||||||
assert_include '<tag>', html_part.body.encoded
|
assert_include '<tag>', html_part.body.encoded
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_should_raise_delivery_errors_when_raise_delivery_errors_is_true
|
||||||
|
mail = Mailer.test_email(User.find(1))
|
||||||
|
mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error"))
|
||||||
|
|
||||||
|
ActionMailer::Base.raise_delivery_errors = true
|
||||||
|
assert_raise Exception, "delivery error" do
|
||||||
|
mail.deliver
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
ActionMailer::Base.raise_delivery_errors = false
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_should_log_delivery_errors_when_raise_delivery_errors_is_false
|
||||||
|
mail = Mailer.test_email(User.find(1))
|
||||||
|
mail.delivery_method.stubs(:deliver!).raises(Exception.new("delivery error"))
|
||||||
|
|
||||||
|
Rails.logger.expects(:error).with("Email delivery error: delivery error")
|
||||||
|
ActionMailer::Base.raise_delivery_errors = false
|
||||||
|
assert_nothing_raised do
|
||||||
|
mail.deliver
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def last_email
|
def last_email
|
||||||
|
|
Loading…
Reference in New Issue