Class: Rex::Proto::Sms::Client
- Inherits:
-
Object
- Object
- Rex::Proto::Sms::Client
- Defined in:
- lib/rex/proto/sms/client.rb
Instance Attribute Summary collapse
-
#carrier ⇒ Symbol
The service provider for the phone numbers.
-
#smtp_server ⇒ Rex::Proto::Sms::Model::Smtp
The Smtp object with the Smtp settings.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Rex::Proto::Sms::Client
constructor
Initializes the Client object.
-
#send_text_to_phones(phone_numbers, subject, message) ⇒ void
Sends a text to multiple recipients.
Constructor Details
#initialize(opts = {}) ⇒ Rex::Proto::Sms::Client
Initializes the Client object.
24 25 26 27 28 29 |
# File 'lib/rex/proto/sms/client.rb', line 24 def initialize(opts={}) self.carrier = opts[:carrier] self.smtp_server = opts[:smtp_server] validate_carrier! end |
Instance Attribute Details
#carrier ⇒ Symbol
Returns The service provider for the phone numbers.
10 11 12 |
# File 'lib/rex/proto/sms/client.rb', line 10 def carrier @carrier end |
#smtp_server ⇒ Rex::Proto::Sms::Model::Smtp
Returns The Smtp object with the Smtp settings.
14 15 16 |
# File 'lib/rex/proto/sms/client.rb', line 14 def smtp_server @smtp_server end |
Instance Method Details
#send_text_to_phones(phone_numbers, subject, message) ⇒ void
This method returns an undefined value.
Sends a text to multiple recipients.
39 40 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 |
# File 'lib/rex/proto/sms/client.rb', line 39 def send_text_to_phones(phone_numbers, subject, ) carrier = Rex::Proto::Sms::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 login_type = self.smtp_server.login_type from = self.smtp_server.from smtp = Net::SMTP.new(address, port) begin smtp.enable_starttls_auto smtp.start(helo_domain, username, password, login_type) do recipients.each do |r| = Rex::Proto::Sms::Model::Message.new( from: from, to: r, subject: subject, message: ) smtp.(.to_s, from, r) end end rescue Net::SMTPAuthenticationError => e raise Rex::Proto::Sms::Exception, e. ensure smtp.finish if smtp && smtp.started? end end |