Tutorial section - SMS

Send SMS with SMPP using Go

Sending SMS with the SMPP API using the Go programming language

The gosmpp library can be used to make SMPP requests using Go. This library can be used to submit SMS to an SMS gateway or SMSC.

SMPP requirements and resources

SMPP is the Short Message Peer-to-Peer protocol and is used by applications for sending and receiving SMS. An SMPP client can be used to connect to an SMSC or SMS gateway using the SMPP protocol. An SMPP account, including special Developer accounts, can quickly and easily be obtained for using the Melrose Labs Tyr SMS Gateway or SMSC Simulator. The following are required to send SMS with SMPP:

Go requirements and resources

Go is a programming language and can be used to quickly and easily add SMS support for programmatically sending and receiving SMS messages. Use it for transactional messaging and notifications between your application and mobiles. The following are required to send SMS using Go:

  • Go
    The Go (aka Golang) programming language

Requirements and resources

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

  • gosmpp
    SMPP (v3.4) Client Library for Go

Install

go install github.com/linxGnu/gosmpp@latest

SMPP Flow

The code connects to the server, then establishes an SMPP transceiver bind by sending a bind_transceiver SMPP PDU. It receives a bind_transceiver - resp with a positive "Ok" acknowledgement.

A submit_sm PDU is then sent by the code to send the message. The message ID for the submission is returned in the submit_sm - resp.

When the message is delivered, the delivery receipt is returned in the deliver_sm PDU and acknowledged by the code with a deliver_sm - resp.

The session is then closed by the code sending an unbind PDU, which is acknowledged with a unbind - resp. The TCP session is then closed.

SMPP flow

Code

Create the file main.go containing the code below and the accompanying go.mod. Replace the hostname smscsim.smpp.org, port 2775, SYSTEMID and PASSWORD values with those for the SMPP API account from your provider. Alternatively, use SMPP credentials for the Melrose Labs SMSC Simulator or the smpp.org SMSC simulator.

The following example Go code opens an SMPP transceiver bind to smscsim.smpp.org on port 2775 (SMPP port), and then sends the message Hello World #$£ to mobile number 447712345678 from the source/sender address MelroseLabs. The message ID in MessageId is that returned from smscsim.smpp.org after a successful submission. The code will keep the SMPP session open for 5 seconds, during which a delivery receipt will be received if the message is delivered during this time.

main.go
Editor
Output
go.mod
module example

go 1.17

require github.com/linxGnu/gosmpp v0.1.6

require golang.org/x/text v0.7.0 // indirect

Run main.go:

% go run main.go
SubmitSMResp:&{base:{Header:{CommandLength:53 CommandID:SUBMIT_SM_RESP CommandStatus:ESME_ROK SequenceNumber:3} OptionalParameters:map[]} MessageID:1f1ced792041033a07f15c76aa5a7d4ff8b9}
DeliverSM:&{base:{Header:{CommandLength:238 CommandID:DELIVER_SM CommandStatus:ESME_ROK SequenceNumber:1} OptionalParameters:map[30:{Tag:30 Data:[49 102 49 99 101 100 55 57 50 48 52 49 48 51 51 97 48 55 102 49 53 99 55 54 97 97 53 97 55 100 52 102 102 56 98 57 0]} 1059:{Tag:1059 Data:[3 0 0]} 1063:{Tag:1063 Data:[2]}]} ServiceType: SourceAddr:447712345678 DestAddr:MelroseLabs EsmClass:4 ProtocolID:0 PriorityFlag:0 ScheduleDeliveryTime: ValidityPeriod: RegisteredDelivery:0 ReplaceIfPresentFlag:0 Message:{SmDefaultMsgID:0 message: enc:0x1050bafa0 udHeader:[] messageData:[105 100 58 49 102 49 99 101 100 55 57 50 48 52 49 48 51 51 97 48 55 102 49 53 99 55 54 97 97 53 97 55 100 52 102 102 56 98 57 32 115 117 98 58 48 48 48 32 100 108 118 114 100 58 48 48 49 32 115 117 98 109 105 116 32 100 97 116 101 58 50 51 48 50 50 49 49 55 53 54 32 100 111 110 101 32 100 97 116 101 58 50 51 48 50 50 49 49 55 53 54 32 115 116 97 116 58 68 69 76 73 86 82 68 32 101 114 114 58 48 48 48 32 116 101 120 116 58 0] withoutDataCoding:false}}
2023/02/21 17:56:22 id:1f1ced792041033a07f15c76aa5a7d4ff8b9 sub:000 dlvrd:001 submit date:2302211756 done date:2302211756 stat:DELIVRD err:000 text:@ <nil>
2023/02/21 17:56:22 id:1f1ced792041033a07f15c76aa5a7d4ff8b9 sub:000 dlvrd:001 submit date:2302211756 done date:2302211756 stat:DELIVRD err:000 text:@

The above shows a connection being made to smscsim.smpp.org on port 2775 and an SMPP transmitter bind (BindType.BIND_TX) being established using the SMPP system ID "SYSTEMID" and password "PASSWORD".

A message is then submitted to the SMSC/SMS gateway using session.submitShortMessage() (sends an SMPP submit_sm PDU), and a response (submit_sm_resp PDU) is received from the SMSC/SMS gateway with the message ID for the submitted message (MessageID: 1f1ced792041033a07f15c76aa5a7d4ff8b9).

Finally, a delivery receipt is received (deliver_sm PDU) indicating the message was delivered.


SMPP over TLS

Use TLSDialer instead of gosmpp.NonTLSDialer for SMPP over TLS. The port number should be changed to the TLS port number of the provider.

Using in production

Whatever the language or API, you can send SMS and receive SMS between applications and mobiles for a wide range of uses with any of the trusted and reliable CPaaS services from Melrose Labs. Take a look at our Messaging, SMS gateway and Bulk SMS solutions, and sign-up for a Developer account on our Tyr SMS Gateway service to try us out.

We provide a wide range of CPaaS services and infrastructure to organisations, including cloud platforms that enable you to run your own SMS gateway.

Get in contact with us to find out more about CPaaS voice, messaging, video and identity from Melrose Labs.

Testing

For testing your application's SMS support when using the SMPP protocol, we recommend starting with the Melrose Labs SMSC Simulator service to simulate SMS message delivery to mobiles (MT SMS) and simulate SMS messages from mobiles (MO SMS). The SMSC Simulator supports SMPP v3.3, v3.4 and v5.

SMSC Simulator

For live testing and delivery to mobiles, use the reliable and dependable Melrose Labs Tyr SMS Gateway for A2P, P2A, bulk, wholesale and business SMS, text marketing and other uses. The Melrose Labs Tyr SMS Gateway supports REST and SMPP APIs.

Tyr SMS Gateway

Alternative APIs and languages

Other APIs covered in our tutorials that can be used for sending and receiving SMS using Go include: REST

Other languages covered in our tutorials that can be used for sending and receiving SMS with SMPP include: Python, PHP, Java, C++, C#, Perl, Node.js, Ruby

Find out more...

Please provide your name.
Please provide a valid company name.
Please type your message.
Please provide a valid email address.