Guest User

Untitled

a guest
Feb 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. require "openssl"
  2. require "net/smtp"
  3.  
  4. require "openssl"
  5. require "net/smtp"
  6.  
  7. Net::SMTP.class_eval do
  8. private
  9. def do_start(helodomain, user, secret, authtype)
  10. raise IOError, 'SMTP session already started' if @started
  11. check_auth_args user, secret, authtype if user or secret
  12. sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
  13. @socket = Net::InternetMessageIO.new(sock)
  14. @socket.read_timeout = 60 #@read_timeout
  15. @socket.debug_output = STDERR #@debug_output
  16. check_response(critical { recv_response() })
  17. do_helo(helodomain)
  18.  
  19. raise 'openssl library not installed' unless defined?(OpenSSL)
  20. starttls
  21. ssl = OpenSSL::SSL::SSLSocket.new(sock)
  22. ssl.sync_close = true
  23. ssl.connect
  24. @socket = Net::InternetMessageIO.new(ssl)
  25. @socket.read_timeout = 60 #@read_timeout
  26. @socket.debug_output = STDERR #@debug_output
  27. do_helo(helodomain)
  28.  
  29. authenticate user, secret, authtype if user
  30. @started = true
  31. ensure
  32. unless @started
  33. # authentication failed, cancel connection.
  34. @socket.close if not @started and @socket and not @socket.closed?
  35. @socket = nil
  36. end
  37. end
  38.  
  39. def do_helo(helodomain)
  40. begin
  41. if @esmtp
  42. ehlo helodomain
  43. else
  44. helo helodomain
  45. end
  46. rescue Net::ProtocolError
  47. if @esmtp
  48. @esmtp = false
  49. @error_occured = false
  50. retry
  51. end
  52. raise
  53. end
  54. end
  55.  
  56. def starttls
  57. getok('STARTTLS')
  58. end
  59.  
  60. def quit
  61. begin
  62. getok('QUIT')
  63. rescue EOFError
  64. end
  65. end
  66. end
Add Comment
Please, Sign In to add comment