Class: Net::SMTP

Inherits:
Object
  • Object
show all
Defined in:
lib/smtp_tls.rb

Overview

:stopdoc:

Defined Under Namespace

Classes: SMTP_TLS

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_ssl_contextObject



17
18
19
# File 'lib/smtp_tls.rb', line 17

def self.default_ssl_context
  OpenSSL::SSL::SSLContext.new
end

.start(address, port = nil, helo = 'localhost.localdomain', user = nil, secret = nil, authtype = nil, &block) ⇒ Object



21
22
23
24
25
# File 'lib/smtp_tls.rb', line 21

def self.start(address, port = nil, helo = 'localhost.localdomain',
               user = nil, secret = nil, authtype = nil, &block) # :yield: smtp
  smtp = new address, port
  smtp.start helo, user, secret, authtype, &block
end

Instance Method Details

#enable_starttls(context = Net::SMTP.default_ssl_context) ⇒ Object



27
28
29
30
31
# File 'lib/smtp_tls.rb', line 27

def enable_starttls(context = Net::SMTP.default_ssl_context)
  raise 'openssl library not installed' unless defined?(OpenSSL)
  @starttls = :always
  @ssl_context = context
end

#quitObject



58
59
60
61
62
63
# File 'lib/smtp_tls.rb', line 58

def quit
  begin
    getok 'QUIT'
  rescue EOFError
  end
end

#start(helo = 'localhost.localdomain', user = nil, secret = nil, authtype = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/smtp_tls.rb', line 35

def start(helo = 'localhost.localdomain',
          user = nil, secret = nil, authtype = nil) # :yield: smtp
  start_method = @starttls ? :do_tls_start : :do_start

  if block_given?
    begin
      send start_method, helo, user, secret, authtype
      return yield(self)
    ensure
      do_finish
    end
  else
    send start_method, helo, user, secret, authtype
    return self
  end
end

#starttlsObject



52
53
54
# File 'lib/smtp_tls.rb', line 52

def starttls
  getok 'STARTTLS'
end

#tls_old_quitObject



56
57
58
59
60
61
# File 'lib/smtp_tls.rb', line 56

def quit
  begin
    getok 'QUIT'
  rescue EOFError
  end
end

#tls_old_startObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/smtp_tls.rb', line 33

def start(helo = 'localhost.localdomain',
          user = nil, secret = nil, authtype = nil) # :yield: smtp
  start_method = @starttls ? :do_tls_start : :do_start

  if block_given?
    begin
      send start_method, helo, user, secret, authtype
      return yield(self)
    ensure
      do_finish
    end
  else
    send start_method, helo, user, secret, authtype
    return self
  end
end