Python script for sending free SMS to any mobile using

Published: by

  • Categories:

NOTE: This script is not working now. Till that is fixed, refer to this link for a perfectly working sms sending script.

You can use this site to automate sms sending on occurrence of a desired event.. This script is similar to my earliest script, but this time it uses a different site

Its better than the previous scrpt because:-

  • Command line parameters support is now available (ex. ./ -h)
  • way2sms is faster than mycantos
  • The sms sent has the sender number as your number & not something like "TA-Mycantos"

This time I also had to include the feature of urlencode to encode my message bcos this was the way the did on its end while doing POST form..

Also, if the script doesnt work for you, install the addon "View HTTP Headers" in firefox and login to way2sms and goto send sms page.. Enter the mobile number to send and message text. Before pressing send, goto tools-> View HTTP Headers, to show the sidebar & check that the number in the script matches to that shown by http header. For me it was 750000, for my friend it was 950000. So, this varies sometimes and this is done by the way2sms to avoid making of scripts like these.. In the script, this value is set to 950000..

  • If you want to have an idea as to how can script like this be made, take a look at my previous post.

I have checked this script on LINUX with python 2.6 and it works fine.. If you have any problem, feel free to leave comments…


__author__ = """
NAME: Abhijeet Rastogi (shadyabhi)

import cookielib
import urllib2
from getpass import getpass
import sys
from urllib import urlencode
from getopt import getopt

ask_username = True
ask_password = True
ask_message = True
ask_number = True

def Usage():
    print '\t-h, --help:  View help'
    print '\t-u, --username: Username'
    print '\t-p, --password: Password'
    print '\t-n, --number: numbber to send the sms'
    print '\t-m, --message: Message to send'

opts, args = getopt(sys.argv[1:], 'u:p:m:n:h',["username=","password=","message=","number=","help"])

for o,v in opts:
    if o in ("-h", "--help"):
    elif o in ("-u", "--username"):
        username = v
        ask_username = False
    elif o in ("-p", "--password"):
        passwd = v
        ask_password = False
    elif o in ("-m", "--message"):
        message = v
        ask_message = False
    elif o in ("-n", "--number"):
        number = v
        ask_number = False

#Credentials taken here
if ask_username: username = raw_input("Enter USERNAME: ")
if ask_password: passwd = getpass()
if ask_message: message = raw_input("Enter Message: ")
if ask_number: number = raw_input("Enter Mobile number: ")

#Logging into the SMS Site
url = ''
data = 'username='+username+'&password='+passwd+'&Submit=Sign+in'

#Remember, Cookies are to be handled
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

# To fool way2sms as if a Web browser is visiting the site
opener.addheaders = [('User-Agent','Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20091020 Ubuntu/9.10 (karmic) Firefox/3.5.3 GTB7.0')]
    usock =, data)
except IOError:
    print "Check your internet connection"

#urlencode performed.. Because it was done by the site as i checked through HTTP headers

message = urlencode({'message':message})
message = message[message.find("=")+1:]

#SMS sending
send_sms_url = ''
#Check this line with HTTP Headers, if script is not working
send_sms_data = 'custid=undefined&HiddenAction=instantsms&Action=custfrom950000&login=&pass=&MobNo='+number+'&textArea='+message
opener.addheaders = [('Referer','')]

    sms_sent_page =,send_sms_data)
    inp = open("log.html","w")

except IOError:
    print "Check your internet connection( while sending sms)"
print "SMS sent!!!"