Permalink
Browse files

Capture stderr from Sendmail and Exim deliveries

Fixes #215
  • Loading branch information...
1 parent b1b1796 commit 22e4c0a35ae13c1c00d661bc85f9d7600d33d60e @jeremy jeremy committed Jan 27, 2013
View
1 CHANGELOG.rdoc
@@ -11,6 +11,7 @@ Performance:
* Close pull request 488 - Speed up field construction & comparison (bpot)
Bugs:
+* Capture stderr from Sendmail and Exim deliveries (jeremy)
* RFC2822 quoted_string content may be empty (jeremy)
* Calling #to_s on a field with a nil value returns an empty string instead of nil (jeremy)
* The Received header may contain zero name/value pairs, qmail-style (jeremy)
View
2 lib/mail/network/delivery_methods/exim.rb
@@ -47,7 +47,7 @@ def initialize(values)
def self.call(path, arguments, destinations, mail)
check_params(mail)
- IO.popen("#{path} #{arguments}", "w+") do |io|
+ popen "#{path} #{arguments}" do |io|
io.puts mail.encoded.to_lf
io.flush
end
View
12 lib/mail/network/delivery_methods/sendmail.rb
@@ -58,10 +58,20 @@ def deliver!(mail)
end
def self.call(path, arguments, destinations, mail)
- IO.popen("#{path} #{arguments} #{destinations}", "w+") do |io|
+ popen "#{path} #{arguments} #{destinations}" do |io|
io.puts mail.encoded.to_lf
io.flush
end
end
+
+ if RUBY_VERSION < '1.9.0'
+ def self.popen(command, &block)
+ IO.popen "#{command} 2>&1", 'w+', &block
+ end
+ else
+ def self.popen(command, &block)
+ IO.popen command, 'w+', :err => :out, &block
+ end
+ end
end
end
View
16 spec/mail/network/delivery_methods/sendmail_spec.rb
@@ -34,6 +34,22 @@
mail.deliver!
end
+ it "should spawn a sendmail process" do
+ Mail.defaults do
+ delivery_method :sendmail
+ end
+
+ mail = Mail.new do
+ from 'roger@test.lindsaar.net'
+ to 'marcel@test.lindsaar.net, bob@test.lindsaar.net'
+ subject 'invalid RFC2822'
+ end
+
+ Mail::Sendmail.should_receive(:popen).with('/usr/sbin/sendmail -i -t -f "roger@test.lindsaar.net" marcel@test.lindsaar.net bob@test.lindsaar.net')
+
+ mail.deliver!
+ end
+
describe "return path" do
it "should send an email with a return-path using sendmail" do

0 comments on commit 22e4c0a

Please sign in to comment.