summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorjohn hackett <john.hackett@bytemark.co.uk>2013-02-07 15:49:47 +0000
committerjohn hackett <john.hackett@bytemark.co.uk>2013-02-07 15:49:47 +0000
commitd0f71b46739bd858797de058600bc2b30e5155f2 (patch)
tree8585325e2c87d7ccfe8eda9eae8575bc1cdbac30 /lib
parent06a4e49a73789d25c715f9ff6c6c5c679f292c7c (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.
Diffstat (limited to 'lib')
-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: