summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjohn.hackett@bytemark.co.uk <john.hackett@bytemark.co.uk>2013-02-07 15:49:47 +0000
committerjohn.hackett@bytemark.co.uk <john.hackett@bytemark.co.uk>2013-02-07 15:49:47 +0000
commit78a361d08817c438b9b3daa7c3acb01cd07119ab (patch)
tree9f45208b02823f2d4e4f218d22ebc349825eb26d
parentb4df9dfd5b2158368a4f4adee7a010673c4308a6 (diff)
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.
-rw-r--r--lib/custodian/protocoltest/smtprelay.rb31
1 files changed, 26 insertions, 5 deletions
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: