You are here:

ActiveXperts.com > SMS and MMS Toolkit > About SMS > SMS Delivery Reports with SMPP protocol

ActiveXperts SMS and MMS ToolkitAdd SMS and MMS capabilities to any Windows or .NET application

Quicklinks


SMS Delivery Reports with SMPP protocol

There are two ways to verify the delivery of SMS messages.

  • Query the status of the message
  • Request delivery reports from the provider

Query the status of the message

When a message is send using the SMPP protocol, the provider returns a message reference. Using this reference, we can query the provider for the delivery status of this message. This is done by sending a 'query_sm' packet to the provider. If the message reference is known by the provider, it responds with a 'query_sm_resp' packet. This packet holds the status of the message. This can be one of the following values:

Status Number Status Explanation
0SCHEDULEDThe message is scheduled for later sending.
1ENROUTEThe message is enroute.
2DELIVEREDThe message was successfully delivered.
3EXPIREDThe SMSC was unable to deliver the message in a specified amount of time. For instance when the phone was turned off.
4DELETEDThe message was deleted.
5UNDELIVERABLEThe SMS was unable to deliver the message.For instance, when the number does not exist.
6ACCEPTEDThe SMS was accepted and will be send.
7UNKNOWNUnknown error occured.
8REJECTEDThe message was rejected. The provider could have blocked phonenumbers in this range.
9SKIPPEDThe message was skipped.

The disadvantage of this method is, that you have to poll once in a while to get the current message status. When a lot of messages are enroute for a couple of hours, this will cause heavy data traffic. Most providers recommend you to request delivery reports instead of querying, because there is only data sent by the provider when the status of a message has changed.

Request delivery reports from the provider

The best way to check the status of each message sent, is to ask for delivery reports. This can be done by setting the 'registered_delivery' value of the 'submit_sm' packet. This parameter can have one of the following values:

Value Meaning
0Do not send delivery reports
1Always send delivery reports
2Send delivery report in case of an error
3Send delivery report only when message is delivered

By setting this value to '1', the provider will send a delivery report to the client every time the status of this message changes. You can set this value per message.

The delivery reports are sent to the client using the 'deliver_sm' packet. This is the same packet as used to deliver incoming messages. To detect whether a 'deliver_sm' is a delivery report or a message, you have to check the 'esm_class' field. If bit 2 of this byte is set ( 0x04 ), it is a delivery report. To use delivery reports, you have to setup a transceiver connection to the SMPP provider, because you are going to send and receive messages. The delivery status is encoded in the 'short_message' field as an ASCII text message. This format is product specific, but the following format is used by most SMPP providers:

id:c449ab9744f47b6af1879e49e75e4f40 sub:001 dlvrd:0 submit date:0610191018 done date:0610191018 stat:ACCEPTD err:0 text:This is an Acti
id:7220bb6bd0be98fa628de66590f80070 sub:001 dlvrd:1 submit date:0610190851 done date:0610190951 stat:DELIVRD err:0 text:This is an Acti
id:b756c4f97aa2e1e67377dffc5e2f7d9b sub:001 dlvrd:0 submit date:0610191211 done date:0610191211 stat:REJECTD err:1 text:This is an Acti
id:bd778cd76ae9e79da2ddc8188c68f8c1 sub:001 dlvrd:0 submit date:0610191533 done date:0610191539 stat:UNDELIV err:1 text:This is an Acti
Field Meaning
idThe message reference of the message.
subSub-ID, not used.
dlvrdValue '1' when the message has been delivered, if the message is still pending '0'.
submit dateSubmission date and time.
done dateDate and time the status has changed, or message delivery time when stat is set to 'DELIVRD'.
statCurrent status of the message.
errAdditional error code, provider specific.
textPart of the original message text.

When using SMPP version 3.4, sometimes the message has some optional parameters (TLV's) attached containing the message state, message reference and a network error code. Please refer to the SMPP version 3.4 documentation on how to use these TLV's.

Using delivery reports in the ActiveXperts SMS and MMS Toolkit

The SMS and MMS Toolkit supports both methods to retrieve the delivery status of a message. We recommend to use the second method, because it causes less data traffic.

To use this method you have to connect with the 'SystemMode' property set to 'asSMPP_MODE_TRANSCEIVER'. Because the connection is setup for both sending and receiving, the SMS component will be listening for incoming delivery reports and store them in its internal cache memory.

Once the connection has been established using the 'Connect' function, you can submit messages. If a message is accepted by the provider it will return the reference number for this message. This reference number is stored in the 'MessageReference' property.

To query the status of a message, you have to set the 'MessageReference' property first. Now you can call the 'QueryStatus' function. The QueryStatus will check the internal cache of the SMS component if there is a delivery report available for the given message reference. If the operation was successfull ( LastError = 0 ), the following properties will be set:

Poperty Meaning
StatusCodeThe status of the message. See the above table for possible values
StatusTimeThe last time the status has been changed, or the delivery time
StatusTimeSecondsThe last time the status has been changed, or the delivery time, in seconds since 1-1-1970

You can use the 'GetStatusDescription' function to convert 'StatusCode' to a readable status.

The following VBScript code sample demonstrates how to use delivery reports with the SMS and MMS Toolkit:

Dim objSmpp
Dim objConstants
Dim strStatus
Dim strRef

Set objSmpp                 = CreateObject ( "ActiveXperts.Smpp" )
Set objConstants            = CreateObject ( "ActiveXperts.SmsConstants" )

objSmpp.Server              = "smpp.activexperts-labs.com"
objSmpp.SystemID            = "AX008"
objSmpp.SystemPassword      = "812056"

objSmpp.SystemMode          = objConstants.asSMPPMODE_TRANSCEIVER			' connect as Transceiver
objSmpp.SystemVersion       = objConstants.asSMPPVERSION_34				' use SMPP version 3.4

objSmpp.Connect

If ( objSmpp.LastError ) Then
    WScript.Echo  "Connect failed: " & objSmpp.GetErrorDescription ( objSmpp.LastError )
    WScript.Quit
End If

objSmpp.MessageData         = "delivery report test"
objSmpp.MessageRecipient    = "+31647134225"
objSmpp.RequestStatusReport = True

objSmpp.Send

If ( objSmpp.LastError ) Then
    WScript.Echo  "Send failed: " & objSmpp.GetErrorDescription ( objSmpp.LastError )
    objSmpp.Disconnect
    WScript.Quit
End If

strRef = objSmpp.MessageReference

WScript.Echo "Message submitted, ID = " & strRef							' Store message reference

For i = 1 To 20
    
    WScript.Sleep  5000  
    
    objSmpp.MessageReference = strRef								' Set message reference
    objSmpp.QueryStatus										' Query the delivery status
    
    strStatus = "Message status after " & i * 5 & " seconds: " & objSmpp.GetStatusDescription ( objSmpp.StatusCode )
    
    WScript.Echo strStatus
Next

objSmpp.Disconnect

WScript.Echo "Ready."

This VBScript will generate the following output:

Message submitted, ID = 00000E73

Message status after  5 seconds: Scheduled
Message status after 10 seconds: Enroute
Message status after 15 seconds: Enroute
Message status after 20 seconds: Enroute
Message status after 25 seconds: Enroute
Message status after 30 seconds: Enroute
Message status after 35 seconds: Enroute
Message status after 40 seconds: Enroute
Message status after 45 seconds: Enroute
Message status after 50 seconds: Enroute
Message status after 55 seconds: Enroute
Message status after 60 seconds: Enroute
Message status after 65 seconds: Enroute
Message status after 70 seconds: Enroute
Message status after 75 seconds: Enroute
Message status after 80 seconds: Enroute
Message status after 85 seconds: Enroute
Message status after 90 seconds: Enroute
Message status after 95 seconds: Enroute
Message status after 100 seconds: Delivered
Ready.
Ready.

To use the first method (querying the provider), justy replace the 'objSmpp.RequestStatusReport = True' with 'objSmpp.RequestStatusReport = False'.