How to Send a Cell Phone a Text Message With a Python Script

by Christopher Hanson

An SMS message, also known as a text message, is essentially an email sent to a mobile phone. The capacity to communicate between computers and cell phones via SMS messaging is increasingly important. Google has developed a library that communicates with the Python programming language allowing programmers to access Gmail accounts. Programmers use the Gmail account as a launching point for SMS messages. Gmail accounts are ideal for mass text messaging because they have a large capacity for responses.

Sign up for a Gmail account by filling out the form.

Download the latest version of the Google library for Python.

Right click the zip file and select "Extract." A dialog box will pop up requesting a target location to extract the zip file. Select the "Documents" directory and click "Extract."

Launch the Microsoft command prompt. Click "Start," "Run," then type "CMD.EXE" and press "Enter."

Move to the library directory. At the command prompt, type "cd c:\Documents\gdata-2.0.12" then press "Enter."

Build and install the library. At the command prompt, type "python setup.py build" then press "Enter." Type "python.py install" then press "Enter."

Launch the Python line editor. At the command prompt, type "python" then press "Enter." The prompt will change to ">>>" to indicate that the Python editor is active.

Import the Gmail library and text message module. At the command prompt, type "import libgmail" then press "Enter." Type "from TextMessaging import *" then press "Enter."

Register the sender information. At the command prompt, type: sender = Sender("<GMAIL_USER>", "<GMAIL_PASS>") Replace <GMAIL_USER> with the login name from the Gmail account. Replace <GMAIL_PASS> with the password for the Gmail account then press "Enter."

Register the text message information. At the command prompt, type: smsMessage = TextMessage("<SUBJECT>", "<BODY>") Replace <SUBJECT> with the subject of the message. Replace <BODY> with the body of the message then press "Enter."

Register the carrier data. At the command prompt, type: CARRIERS = {"Alltel":"alltelmessage.com", "ATT":"mobile.mycingular.com", "Rogers":"pcs.rogers.com", "Sprint":"messaging.sprintpcs.com", "tMobile":"t-mobile.net", "Telus":"msg.telus.com", "Verizon":"vtext.com"} then press "Enter."

Register the receiver of the text message. At the command prompt, type: receiver = Receiver("<PHONE NUMBER>", "<CARRIER>") Replace <PHONE NUMBER> with the phone number of the person who will receive the text message. Replace <CARRIER> with the name of the carrier the person uses. Make sure to type the carrier name exactly the way it appears in the step where the carrier was registered. The carrier name is case sensitive.

Send the message. At the command prompt, type: sender.sendMessage(receiver, smsMessage) then press "Enter."

About the Author

Chris Hanson started writing music, lyrics, and poetry in 2001 and began writing fiction and nonfiction professionally in 2006. Hanson was first published in the "Grand Forks Herald" in 2004. Hanson is an experienced Web programmer with experience with several operating systems and Web protocols. He completed his Bachelor of Arts in anthropology at the University of Minnesota in just three years.

More Articles

Photo Credits

  • photo_camera New message on 3d rendered cell phone image by Franc Podgor...¡ek from Fotolia.com