Tutorial section - SMS

Send SMS with SMPP using C++

Sending SMS with the SMPP API using the C++ programming language

The cpp-smpp library can be used to make SMPP requests using C++. This library can be used to submit SMS to an SMS gateway or SMSC.

SMPP requirements

SMPP is the Short Message Peer-to-Peer protocol for conveying SMS operations. An SMPP account can easily be obtained for using the Tyr SMS Gateway or SMSC Simulator. The following are required to send SMS with SMPP:

C++ requirements

Ruby is a programming language and can be used to quickly and easily add SMS support for programmatically sending and receiving SMS messages. The following are required to send SMS using C++:

  • C++ - C++ programming language

Requirements

The following are required to send SMS with SMPP using C++:

  • cpp-smpp - SMPP client implemented in C++

Code

Create the file transmit.cpp containing the code below. Replace the hostname smscsim.melroselabs.com, port 2775, SYSTEMID and PASSWORD values with those from your SMPP API account. Alternatively, replace SYSTEMID and PASSWORD with those allocated to you for use with the Melrose Labs SMSC Simulator.

The following example C++ code opens an SMPP transmitter bind to smscsim.melroselabs.com on port 2775 (SMPP port), and then sends the message Hello World #$£ to mobile number 447712345678 from MelroseLabs. The message ID returned in $messageID is that returned from the SMS gateway or SMSC after a successful submission. The SMPP system ID and password for the SMPP account are contained in SYSTEMID and PASSWORD respectively.

				#include <smpp/smppclient.h>
#include <smpp/gsmencoding.h>
#include <boost/asio.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>

using namespace boost;
using namespace boost::asio;
using namespace boost::asio::ip;
using namespace smpp;
using namespace oc::tools;
using namespace std;

int main(int argc, char** argv)
{
	boost::asio::io_service io_service;
	boost::asio::ip::tcp::resolver resolver(io_service);
	boost::asio::ip::tcp::resolver::query query("smscsim.melroselabs.com", "2775");
	boost::asio::ip::tcp::resolver::iterator iter = resolver.resolve(query);
	
	tcp::endpoint endpoint = iter->endpoint();
	shared_ptr socket(new tcp::socket(io_service));
	socket->connect(endpoint);

	SmppClient client(socket);
	client.setVerbose(true);
	client.bindTransmitter("SYSTEMID", "PASSWORD");

	SmppAddress from("MelroseLabs", smpp::TON_ALPHANUMERIC, smpp::NPI_UNKNOWN);
	SmppAddress to("447712345678", smpp::TON_INTERNATIONAL, smpp::NPI_E164);
	string message = "Hello World €$£";
	string smscId = client.sendSms(from, to, GsmEncoder::getGsm0338(message));

	cout << smscId << endl;
	client.unbind();

	return 0;
}

Build

	g++ transmit.cpp -I/usr/local/include -lsmpp -lboost_system -lboost_regex -lboost_date_time