SMS host sends
Hosts sending SMS messages via Email
Limitations on machine-to-machine SMS Messaging
You can send SMS messages from your cell phone, or a human user can send SMS from many free public web sites. However, when you ask about sending SMS messages via automated IP-enabled systems, you tend to get simplistic answers which ignore the severe limitations placed upon public SMTP (email) servers to prevent relaying SPAM. If you want a PC or Python script to send SMS on a device without phone/data service, then your options are much more limited (and costly). Searching the web returns solutions which are:
- Specific to a single cell-phone provider and subject to change without notice.
- Or by adding an old-fashioned analog phone modem to the computer, thus gaining direct SMS support.
- Or buying a third-party tool which uses a private forwarding service.
- Or subscribing to a pay-per-message SMS forwarding service (typically costs $0.10 to $0.25 per message)
Simple method to send SMS messages via email
This page covers a simple way to generate public SMS messages without using a direct phone-service. The SMS messages can be targeted at your Digi Python-enabled device to trigger function, responses or to enable SMS testing. It makes use of your own ISP or even a gmail account. Some things to note:
- To send email from a simplistic client, you might need to use a different 'server' host name than you use with a full-function email client - for example my own ISP has me enter 'smtp.1and1.com' into a Windows client such as thunderbird or eudora, but requires me to use 'mrelay.perfora.net' for a more automated send-only client.
- You may be required to use a port other than the normal SMTP port of 25 - for example, both gmail.com and performa.net require use of port 587.
- The 'source address' of the SMS message *MIGHT* be meaningless since the code included is attached by the SMTP service.
- In some systems, special logic within the host SMTP-to-SMS tool will automatically return an email response to the original email sender if an SMS response is sent to that code. It is logical to assume this has a short time-out of a few minutes, after which the SMS response will be dropped or misdirected.
- In others, the 'From:' header field of the email must be used to define the return SMS address, and your Python code will need to decode this as part of the actual text message.
[Disclaimer: use of gmail accounts for commercial activities such as machine-to-machine may require service agreements with Google. This example code is provided for educational and testing purposes only.]
# this sample code is designed to run on a host/PC. # Minor changes may be required to run it on a Digi gateway import smtplib smtpserver = 'smtp.gmail.com' AUTHREQUIRED = 1 # if you need to use SMTP AUTH set to 1 smtpuser = 'my_account@gmail.com' # for SMTP AUTH, set SMTP username here smtppass = 'my_password' # for SMTP AUTH, set SMTP password here # note that your password is stored as PLAIN TEXT in this script, # but is sent over the public network encrypted by SSL/TLS # as of Nov-2009 this is the form of an AT&T SMS destination RECIPIENTS = ['555134567@txt.att.net'] msg = 'From: 5557654321\r\n' # put a valid SMS response number here (If you want) msg += '\r\n' # add a blank line to demarcate between HEADER and BODY msg += 'TK101: Level 46prc\r\n' # here is the message - without the blank line this # would be discarded since it looks like invalid header mailServer = smtplib.SMTP('smtp.gmail.com',587) mailServer.set_debuglevel( True) mailServer.ehlo() mailServer.starttls() mailServer.ehlo() mailServer.login(smtpuser, smtppass) mailServer.sendmail(smtpuser, RECIPIENTS, msg) mailServer.close()
Example output
Enabling SMS with default handler of Python, then running this script below results in the output below that (remember that the actual 'message from' is meaningless and the 'FRM:' was created from the SMTP email header
import digisms import time def ping_callback(a): print """\ Message from: %s at: %s ==================== %s ==================== """ % (a.source_addr, a.timestamp, a.message) return h = digisms.Callback(ping_callback) while( True): print '.' time.sleep( 15.0)
Message from: 1010100006 at: 09/11/06,14:44:13-32q ==================== FRM:5557654321 MSG:TK101: Level 46prc ====================
Notice that the entire text message of "FRM:5557654321\r\nMSG:TK101: Level 46prc\r\n" arrives as the text body of the message. Replying to the source address of 1010100006 will have no useful effect.