From 78a361d08817c438b9b3daa7c3acb01cd07119ab Mon Sep 17 00:00:00 2001 From: "john.hackett@bytemark.co.uk" Date: Thu, 7 Feb 2013 15:49:47 +0000 Subject: Changed smtprelay.rb to correctly report success if an smtp connection is refused, times out, or if message sending doesn't return a 250. Reports failure if the responding server gives an smtp 250 for successful message send. --- lib/custodian/protocoltest/smtprelay.rb | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'lib/custodian/protocoltest') diff --git a/lib/custodian/protocoltest/smtprelay.rb b/lib/custodian/protocoltest/smtprelay.rb index 9b144db..0a7dfdc 100644 --- a/lib/custodian/protocoltest/smtprelay.rb +++ b/lib/custodian/protocoltest/smtprelay.rb @@ -26,16 +26,37 @@ module Custodian # this requires love, just trying to get it to run for now.. def run_test @error = nil # for if we've run the test before - message = "This is a test for OPEN SMTP relays." + message = "Subject: SMTP Relay check\nThis is a test for OPEN SMTP relays." begin + Net::SMTP.start(@host,25) do |smtp| - smtp.send_message message, "foo@bar.com", "foo@bar.com" - @error = "Sent message, that's bad." + sent = smtp.send_message message, "noreply@bytemark.co.uk", "noreply@bytemark.co.uk" + + @status = sent.status.to_s + + if @inverted === true + @success = true + @failure = false + else + @success = false + @failure = true + end + + if @status === "250" #and @inverted == true + @error = "NOT OK: message sent on #{@host} with status #{@status}" + return @success + else + @error = "OK: message not sent on #{@host} with status #{@status}" + return @failure + end + end # Net SMTP rescue Exception => ex # for if we fail to send a message; this is a good thing - return false + + @error = "OK: Timed out or connection refused on #{@host} with status #{@status}" + return @failure end end @@ -43,7 +64,7 @@ module Custodian # if the test failed return a suitable error message def error - @error = "Couldn't send message; that's good, really." + @error end # register ourselves with the factory so we're invoked for lines of the form: -- cgit v1.2.1