Module: Ronin::Network::Mixins::ESMTP

Includes:
Mixin
Defined in:
lib/ronin/network/mixins/esmtp.rb

Overview

Adds ESMTP convenience methods and connection parameters to a class.

Defines the following parameters:

  • host (String) - ESMTP host.
  • port (Integer) - ESMTP port.
  • esmtp_login (String) - ESMTP authentication method to use.
  • esmtp_user (String) - ESMTP user to login as.
  • esmtp_password (String) - ESMTP password to login with.

Instance Method Summary collapse

Methods included from Mixin

included

Instance Method Details

#esmtp_connect(options = {}) {|session| ... } ⇒ Net::SMTP (protected)

Creates a connection to the ESMTP server. The host, port, esmtp_login, esmtp_user and esmtp_password parameters will also be used to connect to the ESMTP server.

Parameters:

  • options (Hash) (defaults to: {})

    Additional options.

Options Hash (options):

  • :port (Integer) — default: Ronin::Network::SMTP.default_port

    The port to connect to.

  • :helo (String)

    The HELO domain.

  • :auth (Symbol)

    The type of authentication to use. Can be either :login, :plain, or :cram_md5.

  • :user (String)

    The user-name to authenticate with.

  • :password (String)

    The password to authenticate with.

Yields:

  • (session)

    If a block is given, it will be passed an ESMTP enabled session object.

Yield Parameters:

  • session (Net::SMTP)

    The ESMTP session.

Returns:

  • (Net::SMTP)

    The ESMTP enabled session.



114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/ronin/network/mixins/esmtp.rb', line 114

def esmtp_connect(options={},&block)
  options[:port] ||= self.port
  options[:login] ||= self.
  options[:user] ||= self.esmtp_user
  options[:password] ||= self.esmtp_password

  if self.port
    print_info "Connecting to #{self.host}:#{self.port} ..."
  else
    print_info "Connecting to #{self.host} ..."
  end

  return ::Net.esmtp_connect(self.host,options,&block)
end

#esmtp_message(options = {}, &block) ⇒ Object (protected)

See Also:

  • SMTP.message.


74
75
76
# File 'lib/ronin/network/mixins/esmtp.rb', line 74

def esmtp_message(options={},&block)
  Network::SMTP.message(options,&block)
end

#esmtp_session(options = {}) {|session| ... } ⇒ Object (protected)

Starts a session with the ESMTP server. The host, port, esmtp_login, esmtp_user and esmtp_password parameters will also be used to connect to the ESMTP server.

Parameters:

  • options (Hash) (defaults to: {})

    Additional options.

Yields:

  • (session)

    If a block is given, it will be passed an ESMTP enabled session object. After the block has returned, the session will be closed.

Yield Parameters:

  • session (Net::SMTP)

    The ESMTP session.

See Also:



149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/ronin/network/mixins/esmtp.rb', line 149

def esmtp_session(options={})
  esmtp_connect(options) do |sess|
    yield sess if block_given?

    sess.close

    if self.port
      print_info "Disconnecting from #{self.host}:#{self.port}"
    else
      print_info "Disconnecting from #{self.host}"
    end
  end
end