Tutorial section - SMS

Send SMS with SMPP using Perl

Sending SMS with the SMPP API using the Perl programming language

The Net-SMPP library can be used to make SMPP requests using Perl. This library's higher-level functions can be used to synchronously 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:


The following are required to send SMS with SMPP using Perl:

  • Net-SMPP - Net::SMPP - pure Perl implementation of SMPP 3.4 over TCP


Create the file sendsms.pl 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 Perl 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 $resp->{message_id} of $resp = $smpp->submit_sm() 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.

# Usage: ./sendsms.pl

use Net::SMPP;
use Data::Dumper;

#$Net::SMPP::trace = 1;

$sysid = "SYSTEMID";
$pw = "PASSWORD";
$host = "smscsim.melroselabs.com";
$port = 2775;

$if_vers = 0x34;

### Connect and bind

warn "Connecting and binding";

($smpp, $resp) = Net::SMPP->new_transmitter(
	port => $port,
	system_id => $sysid,
	password => $pw,
	system_type => "",
	interface_version => $if_vers,
	addr_ton => 0x00,
	addr_npi => 0x00,
	address_range => ""
or die "Can't contact server: $!";

### Typical session in synchronous mode

warn "Sending submit_sm";

$resp = $smpp->submit_sm(
	source_addr_ton => 0x05,
	source_addr_npi => 0x00,
	source_addr => "MelroseLabs",
	dest_addr_ton => 0x01,
	dest_addr_npi => 0x01,
	destination_addr => "447712345678",
	data_coding => 0,
	short_message=>"Hello World"

warn Dumper $resp;

$resp = $smpp->unbind();

warn Dumper $resp;
warn "Done.";