Introduction
This article explains how to add the capability of sending text (SMS) messages from a desktop applicaiton.
Background
The article focuses in an implementation using MFC / C++. While looking for a reliable and cheap solution for sending SMS messages programatically, I came across a company named
CardBoardFish which covers 150 countries and provide an easy to use, yet powerful SDK for interfacing from any web site, mobile phone or desktop applicaiton, covering most platforms and development environments. Unfortunately, among the code sampels in their web site, there aren't any C++ samples, so I have decided to develop my own C++ implementation.
Sending SMS Messages Programatically
Most applicaitons and web sites used to send SMS messages as part of their scope or among other functionalities (i.e. sending alerts, etc.) use one of the following methods:
HTTP Web Service - requires using HTTP "GET" method to send a given Web Service a command, using an API, which contains the credentials, parameters and the text for this message.
EMAIL 2 SMS - uses the SMTP protocol to allow sending an email in a unique format, which encodes all required parameters (credentials, sender, reciever, etc.) as part of an Email.
This article focuses on the first method, using a Web Service.
The API
The following table lists all parameters that can (or should) be sent to the Web Service:
Using the code
The code in this article was developed under MFC / C++ using Visual Studio 2010 Ultimate. I used
Cheng Shi's HTTPClient (thanks Cheng!).
In order to use the code for your own application, it is advised to read the specifications for an SDK named
HTTPSMS. Second, you need to open an account and to obtain your user name and password, which can be hardcoded in the source code, or entered during runtime.
The SendSMS Application
The main functionality of our application is obviously sending an SMS, which is done in the following function:
Collapse | Copy Code
BOOL SendSms(CString From, CString CountryCode, CString To,CString Message,CString *Status)
{
BOOL result=FALSE;
wstring user=L"PLACE_YOUR_USERNAME_HERE",pass=L"PLACE_YOUR_PASSWORD_HERE",request=L"";
request=L"http://sms1.cardboardfish.com:9001/HTTPSMS?S=H&UN=";
request+=user; request+=L"&P=";
request+=pass; request+=L"&DA=";
request+=(wstring)(CountryCode+To); request+=L"&SA=";
request+=(wstring)From; request+=L"&M=";
CString EncodedMessage;
CString ccc;
EncodedMessage=ConvertHex(Message)+ConvertHex( L" here you can place your marketing piech, website, etc.");
request+=(wstring)EncodedMessage;
request+=L"&DC=4";
Now we handle the HTTP "GET" request:
Collapse | Copy Code
WinHttpClient client(request);
client.SendHttpRequest(L"GET",true);
wstring httpResponseHeader = client.GetResponseHeader();
wstring httpResponseContent = client.GetResponseContent();
*Status=httpResponseContent.c_str();
return result;
}
Further Reading
Please refer to
another article of mine, this time explaining how to do the same using iOS (IPhone / iPad).
Michael Haephrati , CodeProject MVP 2013