Archive for October, 2009

SMS Frame Work Using Gnokii , Ruby & Mysql – Sending Bulk Sms

SMS Frame Work

Hai Friends,

Now we r going to see , how to send bulk sms using Mysql and Ruby and Gnokii.

For that we need to install following packages.

# To install MySql database:

$ sudo apt-get install mysql-server mysql-client mysql-admin

While install mysql , it will ask Password for root user of mysql database. We need to enter password two times. Type password as “password” itself. It will be safe.

# To install Ruby

$ sudo apt-get install ruby

$ sudo apt-get install libmysql-ruby

# To install Gnokii ( send sms from mobiles )

$ sudo apt-get install gnokii

Connect mobile and system:

To connct the mobile and sys ON the bluetooth in mobile and system,for system use bluetooth dongle no need of any drivers for bluetooth dongle.

In system the bluetooth sysbol apper as


*in bluetooth symbol click and get preference and select “service”

In this sysmbol right click and select “Browse device” and select the u r mobile and click “connect” ,and accept the msg in mobile and give any passky and click ok,now the mobile and system paired successfully.

Now goto terminal type,

$ sudo gedit /etc/gnokiirc

gnokiirc(/etc)-gedit file opened and change the settings as follows

* in 27th line default present like

* #port = aa:bb:cc:dd:ee:ff

* change port = aa:bb:cc:dd:ee:ff and we want the mobile id or address to get(when mobile and sys connected only) type in terminal like

* $ hcitool scan

* it gives some address and copy this .

* Paste in the 27th line like port = aa:bb:cc:dd:ee:ff change port = “u r mobile address”

* enable model = AT in 51th line disable #model=6110

* put like because v use bluetooth connection # connection = serial in 90 th line

* remove # from connection = bluetooth in 101 st line.


*the id of mobile change depend on mobile model

*don’t use china and goriya.. mobiles or try….

*get preference from bluetooth symbol and enable input service and disable serial service

*Use Ubuntu 8.04 for bluetooth it is compatable…

send sms and enjoy:

go to terminal for send single sms to single number


$ echo “ Hai My Dear Friend , Have A Good Day “ | gnokii –sendsms mobileno

# gnokii (double minus symbol ) – – sendsms  9994332225

Press Enter .

now send succeed !…

How to send sms to many numbers by automatically :

Just follow three steps:

Step 1:

Open text editor.

Type the contact person name and type comma ( , ) and followed by contact number and press Enter.

Repeat this process upto we need to add contacts to send sms.




Raj Kumar,9940857450






I saved the text as “Kanchi_Lug_Contacts”. And While type last contact person number in your list, Pl dont press Enter.

Step 2:

Type the follwing in terminal :

$ mysql -u root -p

It will ask to enter Password. U have to type root password for Mysql. ( what u typed passwd while installing mysql )

mysql > create database myphone;

mysql > exit;



require “mysql”

my = Mysql::new(“localhost”, “root”, “password”, “myphone”)

# Here, type host name, root , passwd for root user and finally database.

my.query(“create table kanchilug (sno integer(5) not null auto_increment primary key,name varchar(25),phone varchar(15))”)

my.query(“insert into kanchilug values(1,’Arulalan’,’9994332225′)”)

# To make auto matic sno ( primary key) we need to insert atleast one record.“Kanchi_Lug_Contacts”,”r”)

file.each do |name_and_no|



my.query(“insert into kanchilug values(”,’#{contact[0]}’,’#{contact[1]}’)”)



print ” Kanchi Lug Members Contact Saved ”


Step 3:

# Klug_Send_Sms.rb

require “mysql”

my = Mysql::new(“localhost”, “root”, “password”, “myphone”)

klug_contacts=my.query(“select * from kanchilug”)

klug_contacts.each do |contact|

# Here contact becomes araay which stored ‘sno’, ‘name’, ‘number’

system(“echo ‘ Hi Kanchi Lug Friends , we hv class on sunday 3 pm. v r going to learn about Arduino Board & Python. Same place, come early ‘ | gnokii –sendsms ‘#{contact[2]}’ “)

# gnokii (double minus symbol ) – – sendsms  9994332225

print “Kanchilug msg sent to #{contact[0]} : #{contact[1]} : #{contact[2]} \n ”




print ” Msg Sent To All Kanchi Lug Members Successfully \n”

print “Bye\n”


Thats all….

Here u need to type ur msg with echo “ “ in this program.

Here after u just run the above program only to send sms .

First two steps for setup, initially. ( No need for every time :- )

Yeap !

Enjoy With Ruby and Gnokii by sending bulk sms…

You can download this blog as pdf from here

Regards ,


அருளாளன் . த