Class: Rex::Proto::Mms::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/proto/mms/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Rex::Proto::Mms::Client

Initializes the Client object.

Parameters:

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

Options Hash (opts):

  • Service (Symbol)

    provider name (see Rex::Proto::Mms::Model::GATEWAYS)

  • SMTP (Rex::Proto::mms::Model::Smtp)

    object


24
25
26
27
28
29
# File 'lib/rex/proto/mms/client.rb', line 24

def initialize(opts={})
  self.carrier     = opts[:carrier]
  self.smtp_server = opts[:smtp_server]

  validate_carrier!
end

Instance Attribute Details

#carrierSymbol

Returns The service provider for the phone numbers.

Returns:

  • (Symbol)

    The service provider for the phone numbers.


10
11
12
# File 'lib/rex/proto/mms/client.rb', line 10

def carrier
  @carrier
end

#smtp_serverRex::Proto::Mms::Model::Smtp

Returns The Smtp object with the Smtp settings.

Returns:


14
15
16
# File 'lib/rex/proto/mms/client.rb', line 14

def smtp_server
  @smtp_server
end

Instance Method Details

#send_mms_to_phones(phone_numbers, subject, message, attachment_path = nil, ctype = nil) ⇒ void

This method returns an undefined value.

Sends a media text to multiple recipients.

Parameters:

  • phone_numbers (<String>Array)

    An array of phone numbers.

  • subject (String)

    MMS subject

  • message (String)

    The message to send.

  • attachment_path (String) (defaults to: nil)

    (Optional) The attachment to include

  • ctype (String) (defaults to: nil)

    (Optional) The content type to use for the attachment


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rex/proto/mms/client.rb', line 41

def send_mms_to_phones(phone_numbers, subject, message, attachment_path=nil, ctype=nil)
  carrier     = Rex::Proto::Mms::Model::GATEWAYS[self.carrier]
  recipients  = phone_numbers.collect { |p| "#{p}@#{carrier}" }
  address     = self.smtp_server.address
  port        = self.smtp_server.port
  username    = self.smtp_server.username
  password    = self.smtp_server.password
  helo_domain = self.smtp_server.helo_domain
    = self.smtp_server.
  from        = self.smtp_server.from

  smtp = Net::SMTP.new(address, port)

  begin
    smtp.enable_starttls_auto
    smtp.start(helo_domain, username, password, ) do
      recipients.each do |r|
        mms_message = Rex::Proto::Mms::Model::Message.new(
          message: message,
          content_type: ctype,
          attachment_path: attachment_path,
          from: from,
          to: r,
          subject: subject
        )
        smtp.send_message(mms_message.to_s, from, r)
      end
    end
  rescue Net::SMTPAuthenticationError => e
    raise Rex::Proto::Mms::Exception, e.message
  ensure
    smtp.finish if smtp && smtp.started?
  end
end

#validate_carrier!Object

Validates the carrier parameter.

Raises:


80
81
82
83
84
# File 'lib/rex/proto/mms/client.rb', line 80

def validate_carrier!
  unless Rex::Proto::Mms::Model::GATEWAYS.include?(self.carrier)
    raise Rex::Proto::Mms::Exception, 'Invalid carrier.'
  end
end