Script free SMS via 160by2.com

Courtesy – yet again, Ruby!

  1. #!/usr/bin/env ruby
  2.  
  3. require "rubygems"
  4. require "mechanize"
  5.  
  6. module SMS
  7.  
  8.   class OneSixtyByTwo
  9.     attr_accessor :agent, :uid
  10.     attr_accessor :urls
  11.  
  12.     def initialize(username, password)
  13.       @urls = {
  14.         :login => "http://m.160by2.com",
  15.         :sms => "http://m.160by2.com/SaveCompose.asp?l=1"
  16.       }
  17.       @agent = WWW::Mechanize.new
  18.       login = agent.get(@urls[:login])
  19.       login.forms[0].txtUserName = username
  20.       login.forms[0].txtPasswd = password
  21.       page = login.forms[0].submit
  22.       @uid = page.forms[0].action.split("=")[-1].split("&")[0]
  23.     end
  24.  
  25.     def sms(recepient, message)
  26.       message.gsub!(" ", "+")
  27.       params = {
  28.         "Msg" => @uid,
  29.         "TID" => "",
  30.         "T_MsgId" => "",
  31.         "categoryid" => "28:GoodMorning",
  32.         "cmdSend" => "Send+SMS",
  33.         "txt_mobileno" => recepient,
  34.         "txt_msg" =>  message
  35.       }
  36.  
  37.       page = agent.post(@urls[:sms], params)
  38.       if page.code == "200"
  39.         return true
  40.       else
  41.         return false
  42.       end
  43.     end
  44.   end
  45.  
  46. end
  47.  
  48. mobile = "XXXXXXXXXX"
  49. result = SMS::OneSixtyByTwo.new("your_160by2_username", "your_160by2_password").sms(mobile, "Test message")
  50. if result == true
  51.   puts "SMS sent to #{mobile}"
  52. else
  53.   puts "Error in sending the SMS"
  54. end

Result…

[makuchaku@Warrior ruby]$ ./160by2.rb
SMS sent to XXXXXXXXXX

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

  • jaadu

    hi,
    could you please tell me how can i send sms in asp.net using c#.
    what exactly i want to do is to send a sms to a user who creates an account on my site.

  • http://intensedebate.com/people/makuchaku makuchaku