Below is a detailed walk through of adding SMS notifications to your Rails app


Many of the Ruby on Rails (RoR) application have requirement to send sms notifications to users or to validate their account using OTP SMS to mobile number. Also, bulk SMS texting using sms gateway is still the best way to broadest customer base.

If you have a Ruby on Rails application, It is extremely easy to add such capabilities specially when using a service such as Spring Edge to reach customers and interact with them.

Its easy to add Spring Edge to a Rails application. This article will guide you through the steps of integrating Rails with Spring Edge, More specifically, it will cover:

  • Signing Up with Spring Edge SMS Gateway
  • Generating sms gateway Auth Key and scret
  • Send test sms using API Trigger
  • Integration with Rails Application

Lets get started:

Signing Up With Spring Edge SMS Gateway:
Signing up for Spring Edge is as simple as filling an online form with your name, email and other details. After you sign up you will receive login details by email. Upon login into sms account, you are given trail credits in account to get started with. These credits are spent every time a sms is sent using spring edge web app or sms API.

Generating Auth Key and scret:
Authentication make APIs secure to prevent unauthorised access of our account data. After signing in to sms account, It is mandatory to generate an api key to use RestAPIs and send sms. You can generate api auth key by clicking on Generate new key button of API Keys option under “Developers” menu of sms account. For security purpose half of the API key will be visible in Developer menu of user interface and full API Auth key will be sent to registered email address.

Send test sms with spring edge:
To test message you have two ways web interface and messaging API. With UI, Login into your sms account user interface and enter mobile number in To Mobile Numbers text area by clicking on Compose Message option of Send Message menu. In case of multiple mobile numbers it need to be one mobile number in each line, Click Send now button after selecting sender id and enter text in Message box. You can check sent report for acknowledgement of sent sms.

Send a Test SMS Using API Trigger
To send test message using Spring Edge SMS API, you can combine server url and params as query string to create complete sms gateway api url.
Server URL:



to= '9190xxxxxxxx', //Destination Mobile number
apikey='N3c76xxxxxxxxxxxxxxxxxxxxxx', //Auth key
senderid='SEDEMO', //Sender Name
message='test-message' //sms body

To Execute, You can combine sms server url along with api params and hit this url directly in new tab of your internet browser. Your complete url will look like


Expected Output:


Integration of SMS with Ruby on Rails (ROR) Application:

1. First include Net::HTTP which provides a rich library which can be used to build HTTP user-agents. Net::HTTP is designed to work closely with URI. URI::Generic#host, URI::Generic#port and URI::HTTP#request_uri are designed to work with Net::HTTP.
require ‘net/http’

2.Build SMS API URL and Params to call sms api server as below

smsserver = 'http://web.springedge.com/api/web/send/'
apikey = 'N3c76xxxxxxxxxxxxxxxxxxxxxx'
message = 'Test Message'
messagebody = URI::encode(message)
mobileno = '91903xxxxxxxx'
senderid = 'SEDEMO'

3. Pharse URL

Use Pharse URL class that Parses Strings into URIs

url = URI.parse(smsserver+'?apikey='+apikey+'&sender='+senderid+'&to='+mobileno+'&message='+messagebody)

4. Finally, call api using http request

req = Net::HTTP::Get.new(url.to_s)
res = Net::HTTP.start(url.host, url.port) {|http|

Your complete ROR SMS Gateway Integration code will look like:

require 'net/http'
smsserver = 'http://web.springedge.com/api/web/send/'
apikey = 'N3c76xxxxxxxxxxxxxxxxxxxxxx'
message = 'Test Message'
messagebody = URI::encode(message)
mobileno = '91903xxxxxxxx'
senderid = 'SEDEMO'
url = URI.parse(smsserver+'?apikey='+apikey+'&sender='+senderid+'&to='+mobileno+'&message='+messagebody)
req = Net::HTTP::Get.new(url.to_s)
res = Net::HTTP.start(url.host, url.port) {|http|
puts res.body

You can also use POST method as below

res = Net::HTTP.post_form(uri, 'q' => ['param', 'param'], 'max' => '50')

Deployment on production:

To configuration of sms notifications in a production environment of your application, You need to move to a commercial account from existing Test/Trail sms gateway account. Once commercial account is set-up, You can configure customised sender name.

Leave a Reply

Your email address will not be published. Required fields are marked *