Method: Net::SMTP#initialize

Defined in:
lib/net/smtp.rb

#initialize(address, port = nil, tls: false, starttls: :auto, tls_verify: true, tls_hostname: nil, ssl_context_params: nil) ⇒ SMTP

Creates a new Net::SMTP object.

address is the hostname or ip address of your SMTP server. port is the port to connect to; it defaults to port 25.

If tls is true, enable TLS. The default is false. If starttls is :always, enable STARTTLS, if :auto, use STARTTLS when the server supports it, if false, disable STARTTLS.

If tls_verify is true, verify the server’s certificate. The default is true. If the hostname in the server certificate is different from address, it can be specified with tls_hostname.

Additional SSLContext params can be added to the ssl_context_params hash argument and are passed to OpenSSL::SSL::SSLContext#set_params.

tls_verify: true is equivalent to ssl_context_params: { verify_mode: OpenSSL::SSL::VERIFY_PEER }.

This method does not open the TCP connection. You can use SMTP.start instead of SMTP.new if you want to do everything at once. Otherwise, follow SMTP.new with SMTP#start.



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/net/smtp.rb', line 248

def initialize(address, port = nil, tls: false, starttls: :auto, tls_verify: true, tls_hostname: nil, ssl_context_params: nil)
  @address = address
  @port = (port || SMTP.default_port)
  @esmtp = true
  @capabilities = nil
  @socket = nil
  @started = false
  @open_timeout = 30
  @read_timeout = 60
  @error_occurred = false
  @debug_output = nil
  @tls = tls
  @starttls = starttls
  @ssl_context_tls = nil
  @ssl_context_starttls = nil
  @tls_verify = tls_verify
  @tls_hostname = tls_hostname
  @ssl_context_params = ssl_context_params
end