lib/extended_classes.rb
# opens a socket to the IP/port to see if there is an SMTP server
# there - returns "250 ..." if the server is there, or 
# times out in 5 seconds to prevent hanging the process
opens a socket to the IP/port to see if there is an SMTP server
there - returns "250 ..." if the server is there, or
times out in 5 seconds to prevent hanging the process
opens a socket to the IP / port to see if there is an SMTP server there - returns " 250 ... " if the server is there or times out in 5 seconds to prevent hanging the process
def mta_live?(port)
    tcp_socket = nil
    welcome = nil
    begin
      Timeout.timeout(60) do
        begin
          tcp_socket = TCPSocket.open(self,port)
        rescue Errno::ECONNREFUSED => e
          return "421 Service not available (port closed)"
        end
        begin
          welcome = tcp_socket.gets
          return welcome if welcome[1]!='2'
          tcp_socket.write("QUIT\r\n")
          line = tcp_socket.gets
          return line if line[1]!='2'
        ensure
          tcp_socket.close if tcp_socket
        end
      end
      return "250 #{welcome.chomp[4..-1]}"
    rescue SocketError => e
      return "421 Service not available (#{e.to_s})"
    rescue Timeout::Error => e
      return "421 Service not available (#{e.to_s})"
    end
  end
def mta_live? ( port ) tcp_socket = nil welcome = nil begin Timeout . timeout ( 60 ) do begin tcp_socket = TCPSocket . open ( self , port ) rescue Errno :: ECONNREFUSED => e return "421 Service not available (port closed)" end begin welcome = tcp_socket . gets return welcome if welcome [ 1 ] != '2' tcp_socket . write ( "QUIT\r\n" ) line = tcp_socket . gets return line if line [ 1 ] != '2' ensure tcp_socket . close if tcp_socket end end return "250 #{welcome.chomp[4..-1]}" rescue SocketError => e return "421 Service not available (#{e.to_s})" rescue Timeout :: Error => e return "421 Service not available (#{e.to_s})" end end
opens a socket to the IP/port to see if there is an SMTP server
there - returns "250 ..." if the server is there, or
times out in 5 seconds to prevent hanging the process
opens a socket to the IP / port to see if there is an SMTP server there - returns " 250 ... " if the server is there or times out in 5 seconds to prevent hanging the process
port
<not_specific>