Delivery Reports

Introduction

SMSLib gives you the ability to work with delivery reports (otherwise known as "status report" messages) which will allow you to determine when a sent message has reached its recipient or it failed.

Delivery reports arrive as special inbound messages. They get generated from either the cell provider's Message Center (SMSC) or from the recipient's cell phone. SMSLib does not (by default) request delivery reports but you can easily enable this on a per-message level.

Warning: Delivery reports are network dependent. You might find out that although you do whatever it takes, you don't get delivery reports back. In this case, you are in bad luck as there is nothing you can do in order to activate the delivery reports - except maybe to complain to your cell provider...

Message Reference Numbers

Each message, once submitted for dispatch, gets a number from your cell provider's SMSC. Assume that we have the following two lines which send out a message via SMSLib:

msg = new OutboundMessage("306948494037", "Hello from SMSLib!");
srv.sendMessage(msg);

These lines are taken from the SendMessage example. If you print out the msg object, you will get the following output:

===============================================================================
<< OutboundMessage >>
-------------------------------------------------------------------------------
Gateway Id: modem.com1
Encoding: 7-bit
Date: Sun Dec 21 13:56:23 EET 2008
SMSC Ref No: 226
Recipient: 306948494037
Dispatch Date: Sun Dec 21 13:56:38 EET 2008
Message Status: SENT
Validity Period (Hours): -1
Status Report: true
Source / Destination Ports: -1 / -1
Flash SMS: false
Text: Hello from SMSLib!
PDU data: C8329BFD0699E5EF3668DA9C32D3E210
-------------------------------------------------------------------------------

Notice the SMSC Ref No value: An outbound message object will get this number after successfully sent. This Reference Number is the key to your message. Unfortunatelly this is not a unique value. This value gets cycled between 1 and 255, so its not a "good" key by itself. In order to create a good key, you should combine this with your recipient's number. Theoretically this is not a "good" key as well, but the chances are that this combination is unique enough.

Requesting a delivery report

If you need to request a delivery report, modify the previous two lines as follows:

msg = new OutboundMessage("306948494037", "Hello from SMSLib!");
msg.setStatusReport(true);
srv.sendMessage(msg);

Notice the setStatusReport() method call. This will enable the delivery report for the specific message!

Processing delivery status messages

As mentioned before, delivery/status report message are special inbound messages. So, you should expect it to be forwarded via your normal inbound processing methods. The delivery report message is a StatusReportMessage class object and has a MessageType of Message.MessageTypes.STATUSREPORT. Check each inbound message either for a class match or for a MessageType match in order to find out if it is a normal inbound message or a status report message.

Running the ReadMessages as an example, you will notice the following message within your list of received messages:

===============================================================================
<< StatusReportMessage >>
-------------------------------------------------------------------------------
Gateway Id: modem.com1
Encoding: 7-bit
Date: null
Text: 00 - Succesful Delivery.
PDU data: null
Originator:
Original Recipient: 306948494037
Delivery Status: DELIVERED
SMSC Ref No: 226
Memory Index: 3
Multi-part Memory Index:
Memory Location: SM
Source / Destination Ports: -1 / -1
===============================================================================

There is some important information in this message:

With the first two values, you create the key in order to find out to which message this delivery report refers to. The status gives you the actual status of the message (has it been delivered, failed, or delayed). Look at the StatusReportMessage.DeliveryStatuses enumeration for valid status values.