Module: Ronin::Network::Mixins::SMTP

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

Overview

Adds SMTP convenience methods and connection parameters to a class.

Defines the following parameters:

  • host (String) - SMTP host.
  • port (Integer) - SMTP port.
  • smtp_login (String) - SMTP authentication method.
  • smtp_user (String) - SMTP user to login as.
  • smtp_password (String) - SMTP password to login with.

Instance Method Summary collapse

Methods included from Mixin

included

Instance Method Details

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

Creates a connection to the SMTP server. The host, port, smtp_login, smtp_user and smtp_password parameters will also be used to connect to the 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 SMTP session object.

Yield Parameters:

  • session (Net::SMTP)

    The SMTP session.

Returns:

  • (Net::SMTP)

    The SMTP session.



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

def smtp_connect(options={},&block)
  options[:port] ||= self.port
  options[:login] ||= self.
  options[:user] ||= self.smtp_user
  options[:password] ||= self.smtp_password

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

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

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

See Also:



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

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

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

Starts a session with the SMTP server. The host, port, smtp_login, smtp_user and smtp_password parameters will also be used to connect to the server.

Yields:

  • (session)

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

Yield Parameters:

  • session (Net::SMTP)

    The SMTP session.

See Also:



144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/ronin/network/mixins/smtp.rb', line 144

def smtp_session(options={},&block)
  smtp_connect(options) do |sess|
    yield sess if block_given?
    sess.close

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