Permalink
Browse files

Added :raise_delivery_errors to Mail::Message

  • Loading branch information...
mikel committed Jan 23, 2010
1 parent 619408e commit 84b21d19ec766f637433a348855d81942db78b2e
Showing with 29 additions and 4 deletions.
  1. +4 −0 CHANGELOG.rdoc
  2. +1 −1 Rakefile
  3. +8 −2 lib/mail/message.rb
  4. +1 −1 lib/mail/version.rb
  5. +15 −0 spec/mail/network_spec.rb
View
@@ -1,3 +1,7 @@
+== Sat Jan 23 23:49:50 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
+
+* Added :raise_delivery_errors to Mail::Message, if set to false will silently rescue all errors raised by the delivery methods, set to true by default
+
== Sat Jan 23 23:28:42 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
* Added :perform_deliveries to mail, will not actually call deliver on the delivery method if this is set to false, set to true by default.
View
@@ -12,7 +12,7 @@ require 'bundler'
spec = Gem::Specification.new do |s|
s.name = "mail"
- s.version = "2.0.3"
+ s.version = "2.0.5"
s.author = "Mike Lindsaar"
s.email = "raasdnil@gmail.com"
s.homepage = "http://github.com/mikel/mail"
View
@@ -101,6 +101,7 @@ def initialize(*args, &block)
@html_part = nil
@perform_deliveries = true
+ @raise_delivery_errors = true
@delivery_method = Mail.delivery_method.dup
@delivery_notification_observers = []
@@ -118,6 +119,7 @@ def initialize(*args, &block)
end
attr_accessor :perform_deliveries
+ attr_accessor :raise_delivery_errors
def register_for_delivery_notification(observer)
@delivery_notification_observers << observer
@@ -137,8 +139,12 @@ def inform_observers
# mail.deliver!
def deliver
if perform_deliveries
- delivery_method.deliver!(self)
- Mail.deliveries << self
+ begin
+ delivery_method.deliver!(self)
+ Mail.deliveries << self
+ rescue Exception => e # Net::SMTP errors or sendmail pipe errors
+ raise e if raise_delivery_errors
+ end
end
inform_observers
end
View
@@ -3,7 +3,7 @@ module Mail
module VERSION
MAJOR = 2
MINOR = 0
- TINY = 3
+ TINY = 5
STRING = [MAJOR, MINOR, TINY].join('.')
end
View
@@ -252,6 +252,21 @@ def message
MyObserver.should_receive(:delivered_email).with(message).once
message.deliver
end
+
+ it "should pass on delivery errors if raised" do
+ delivery_agent = MyDeliveryMethod.new
+ message.stub!(:delivery_method).and_return(delivery_agent)
+ delivery_agent.stub!(:deliver!).and_raise(Exception)
+ doing { message.deliver }.should raise_error(Exception)
+ end
+
+ it "should not pass on delivery errors if raised raise_delivery_errors is set to false" do
+ delivery_agent = MyDeliveryMethod.new
+ message.stub!(:delivery_method).and_return(delivery_agent)
+ message.raise_delivery_errors = false
+ delivery_agent.stub!(:deliver!).and_raise(Exception)
+ doing { message.deliver }.should_not raise_error(Exception)
+ end
end
end

0 comments on commit 84b21d1

Please sign in to comment.