[PythonCE] Sending SMS messages from PythonCE

Silas S. Brown ssb22 at cam.ac.uk
Mon Feb 14 13:20:22 CET 2011


Hi, I wonder if you'd like to add this to the examples.  It's a
Python function to send an SMS message (text message) from PythonCE.
Tested on Windows Mobile 6.0 Smartphone, should work on most others.
Took me a while to figure out and I thought others might benefit.

import ctypes
import ctypes.wintypes as wintypes
def send_SMS_message(number, unicode_text):
  handle = wintypes.DWORD()
  ret = ctypes.cdll.sms.SmsOpen(u"Microsoft Text SMS Protocol",
      wintypes.DWORD(2),ctypes.byref(handle),None)
  if not (ret==0 and handle): raise Exception("SmsOpen error")
  class SMSaddress(ctypes.Structure):
    _fields_ = [("smsatAddressType",ctypes.c_int),
      ("ptsAddress",ctypes.c_wchar * 256)]
  unicode_text = u"" + unicode_text # make sure it's Unicode
  ret = ctypes.cdll.sms.SmsSendMessage(handle,None,
      ctypes.byref(SMSaddress(0,number)),None,unicode_text,
      wintypes.DWORD(2*len(unicode_text)),"\0\0\0\0\3\0\0\0\0\0\0\0",
      wintypes.DWORD(12),ctypes.c_int(0),wintypes.DWORD(0),None)
  if not ret==0: raise Exception("SmsSendMessage error")
  ctypes.cdll.sms.SmsClose(handle)

Thanks.    Silas

PS: Thanks for developing PythonCE, much appreciated.  I'm using
it for my language-learning program and front-end to eSpeak speech synth
http://people.pwf.cam.ac.uk/ssb22/gradint/ among other things.

-- 
Silas S Brown http://people.pwf.cam.ac.uk/ssb22


More information about the PythonCE mailing list