Monday, October 19, 2009

Retrieving inbox from mobile

For retrieving inbox details from a GSM mobile phone is not simple as the sending messages from phone using PC with the help of a AT Commands. Here we need to check whether your phone store your messages in the SIM memory or phone memory. We need to alter our messages according to the storage type of the messages.

Here are the example in the case of storing the messages inside the inbox.

AT Command

AT // For checking phone connected
AT+CMGF=1 // Setting message format
AT+CSCS="PCCP437" // Setting charset
AT+CPMS="SM" // Selecting sim message storage
AT+CMGL="ALL" // Reading all inbox messages

Function for reading message collection

public ShortMessageCollection ReadSMS(SerialPort port)

// Set up the phone and read the messages
ShortMessageCollection messages = null;

#region Execute Command
// Check connection
ExecCommand(port,"AT", 300, "No phone connected");
// Use message format "Text mode"
ExecCommand(port,"AT+CMGF=1", 300, "Failed to set message format.");
// Use character set "PCCP437"
ExecCommand(port,"AT+CSCS=\"PCCP437\"", 300, "Failed to set character set.");
// Select SIM storage
ExecCommand(port,"AT+CPMS=\"SM\"", 300, "Failed to select message storage.");
// Read the messages
string input = ExecCommand(port,"AT+CMGL=\"ALL\"", 5000, "Failed to read the messages.");

#region Parse messages
messages = ParseMessages(input);

catch (Exception ex)
throw new Exception(ex.Message);

if (messages != null)
return messages;
return null;