Courtesy – yet again, Ruby!
-
#!/usr/bin/env ruby
-
-
require "rubygems"
-
require "mechanize"
-
-
module SMS
-
-
class OneSixtyByTwo
-
attr_accessor :agent, :uid
-
attr_accessor :urls
-
-
def initialize(username, password)
-
@urls = {
-
:login => "http://m.160by2.com",
-
:sms => "http://m.160by2.com/SaveCompose.asp?l=1"
-
}
-
@agent = WWW::Mechanize.new
-
login = agent.get(@urls[:login])
-
login.forms[0].txtUserName = username
-
login.forms[0].txtPasswd = password
-
page = login.forms[0].submit
-
@uid = page.forms[0].action.split("=")[-1].split("&")[0]
-
end
-
-
def sms(recepient, message)
-
message.gsub!(" ", "+")
-
params = {
-
"Msg" => @uid,
-
"TID" => "",
-
"T_MsgId" => "",
-
"categoryid" => "28:GoodMorning",
-
"cmdSend" => "Send+SMS",
-
"txt_mobileno" => recepient,
-
"txt_msg" => message
-
}
-
-
page = agent.post(@urls[:sms], params)
-
if page.code == "200"
-
return true
-
else
-
return false
-
end
-
end
-
end
-
-
end
-
-
mobile = "XXXXXXXXXX"
-
result = SMS::OneSixtyByTwo.new("your_160by2_username", "your_160by2_password").sms(mobile, "Test message")
-
if result == true
-
puts "SMS sent to #{mobile}"
-
else
-
puts "Error in sending the SMS"
-
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.
View Comments to Script free SMS via 160by2.com
jaadu
May 4th, 2010 at 7:51 am
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.
makuchaku
May 4th, 2010 at 3:02 pm
Tryhttp://Fastalerts.in