Skip to content

Instantly share code, notes, and snippets.

@geoffgarside
Created July 29, 2009 00:19
Show Gist options
  • Save geoffgarside/157771 to your computer and use it in GitHub Desktop.
Save geoffgarside/157771 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Usage: $0 hostname email_addr
#
# Performs a basic SMTP delivery check, it connects to the target SMTP server, sends
# a HELO command, then a MAIL FROM followed by a RCPT TO. This should verify that
# the server is a) contactable b) permits the sender and c) accepts the recipient.
require 'socket'
require 'net/telnet'
me = Socket.gethostname
tn = Net::Telnet.new('Host' => ARGV[0], 'Port' => 25, 'Prompt' => /^[0-9]{3}\s.*$/)
puts "Connection established..."
tn.waitfor(/220\s.*$/)
tn.cmd("HELO #{me}")
puts "HELO sent..."
puts "Sending mail from test@#{me} -> #{ARGV[1]}..."
tn.cmd("MAIL FROM: test@#{me}")
puts "SMTP Server Response to RCPT TO..."
puts tn.cmd("RCPT TO: #{ARGV[1]}")
tn.cmd("QUIT")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment