If you have not got a Pocket PC Phone Edition or Windows CE SmartPhone device, sorry this article will not be useful.
Now having got that out of the way, this article will show how to send an SMS to another SMS capable device, using the Windows CE MAPI API (A.K.A. CEMAPI) instead of the supplied SMS APIs.
SMS or Simple Messaging Service is a means of sending a short message (160 characters max) to another SMS capable device via the GSM network. On Pocket PC Phone edition devices and Windows CE Smart phones, when selecting a folder, there should have been at least an ActiveSync and SMS message store and possibly an MMS message store as well.
These message stores hold messages from different transport providers locally on the device.
For the purposes of this article, we will be concentrating on the SMS message store as we want to use this to send a message.
Using the code
To make the code simpler and easier to understand, the bulk of the code uses MFC for the User Interface and ATL for smart pointer support.
If people request it, I may make a Win32 only version available as the relevant code (i.e., not the UI code) only requires ATL and not MFC.
In this article, I am not going through a listing of the creation of the MAPI session and opening of the SMS message store and outbox folder. The code is well commented and provided in the source zip file in the two functions
GetSMSFolder which get the relevant SMS message store and the SMS drafts folder.
So we start looking at the code when we have created a new message in the Outbox folder.
The bulk of the code involves creating the recipients and setting the sender and message status.
First is setting the recipient of the message. To make the code clearer, I have only set one recipient on for the message, although multiple recipients may be set, each one requiring three properties, the type of recipient, the type of address, and the email address.
Unfortunately, I found the code that Microsoft provided for the MAPI samples too complex as they were overshadowed by overly complex memory and pointer manipulation. To that end, I have provided a simpler implementation for recipients.
First, we create the properties that we need for a recipient.
propRecipient.ulPropTag = PR_RECIPIENT_TYPE;
propRecipient.Value.l = MAPI_TO;
propRecipient.ulPropTag = PR_ADDRTYPE;
propRecipient.Value.lpszW = _T("SMS");
propRecipient.ulPropTag = PR_EMAIL_ADDRESS;
propRecipient.Value.lpszW = (LPWSTR)lpszTo;
If you want to add additional recipients to the message, you can expand the
propRecipient to a multiple of three, and add the appropriate recipient type, address type, and address properties.
ADRLIST structure needs to be set with pointers to the recipient properties and the count of the properties. You will need to provide one
ADRENTRY per recipient.
adrlist.cEntries = 1;
adrlist.aEntries.cValues = 3;
adrlist.aEntries.rgPropVals = (LPSPropValue)(&propRecipient);
hr = spMessage->ModifyRecipients(MODRECIP_ADD, &adrlist);
Finally, we set the subject of the message as the text of the SMS body to be sent. Note that the length of the SMS message can be no longer than 160 characters as this is the maximum size of a message that can be sent using the GSM Short Messaging Service.
Lastly, we set the remainder of the properties, which are the sender as the person originating the message, and the message record type to SMS so that is gets enumerated by the transport and get sent correctly. Optionally, the message can have the message flags set which indicate that the message is unsent and originates from me.
props.ulPropTag = PR_SUBJECT;
props.Value.lpszW = (LPWSTR)lpszMessage;
props.ulPropTag = PR_SENDER_EMAIL_ADDRESS;
props.Value.lpszW = (LPWSTR)lpszFrom;
props.ulPropTag = PR_MSG_STATUS;
props.Value.ul = MSGSTATUS_RECTYPE_SMS;
props.ulPropTag = PR_MESSAGE_FLAGS;
props.Value.ul = MSGFLAG_FROMME | MSGFLAG_UNSENT;
hr = spMessage->SetProps(sizeof(props) / sizeof(props),
As all the properties and recipients have now been set on the message, it is safe to call
appropriate message transport provider.
hr = spMessage->SubmitMessage(0);
If you wait a couple of seconds, the message will appear on the phone number you specified in the To field of the message. Also note that the sent message will now appear in the Sent Items folder as you would expect.
I have not included a Win32 or SmartPhone version of the code here at the moment. However, if anyone wants versions of it, email me and I will consider updating the samples to include SmartPhone and a pure Win32 version.
Points of Interest
No revisions thus far.