By using this small Trick we can send SMS to any Indian Mobile number from fullonsms via our Rails Application.
For this we need a gem ‘mechanize’ It will help us to render our html pages, forms, form elements etc .
So let’s go ahead and install this gem for our Rails application.
Add gem ‘mechanize‘ to our Gem file and run bundle install in CMD/Terminal.
Now in terminal go in console mode
$ rails console
Now keep entering following Commands :
$ require ‘mechanize’
$ agent = Mechanize.new
$ page = agent.get(“http://fullonsms.com/login.php”) # Get our login Page.
$ agent.get(“http://fullonsms.com/logout.php?LogOut=1”) # it should result true, as it will be searching for LoginForm in our login page.
$ login_form = page.form(“LoginForm”) # Get the login form
$ login_form.MobileNoLogin = “89XXXXXXX3” # Add your registered 10 Digits Mobile number
$ login_form.LoginPassword = “XXXXXX “ # Your password goes here.
$ page = agent.submit(login_form) # Let’s submit our login form
$ page = agent.get “http://fullonsms.com/home.php?show=contacts” # Render our Landing page
$ page.forms.any? { |form| form.name == “ComposeForm” } # Let’s search for our Compose form, it must return true.
$ compose_form = page.form(“ComposeForm”)
$ compose_form.MobileNos = “9861XXXXXX” # Add 10 digit mobile number to which you want to send Message
$ compose_form.Message = “Hi User, This is a messge sent from my Rails Application !!! ” #Compose your message
$ page = agent.submit(compose_form) # Let’s Submit our message
$ agent.get(“http://fullonsms.com/logout.php?LogOut=1”) #logout of the fullonsms.
Get your message from fullonsms.com on your number 9861XXXXXX ! ( there might be delay if server response is low or fullonsms may not deliver your message if the same message is sent repeatedly to the same number )
For cross checking, You can always check your sent items section.
Issue: At times you may encounter error MobileNoLogin= is nil? ;
Don’t worry, it is an issue with fullonsms. occasionally. Restarting the server may fix it.