Sending-Receiving SMS through an Exe (Server)

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Code ExampleArticle
Created: kiran10182 (28 May 2007)
Last edited: hamishwillee (18 Sep 2012)



It is a common practice to send messages and read incoming messages from Messaging server and parse them accordingly. Developer genearally prefers such a functionality as being server side implementation which can be developed using GUI-less Exe.

This article is about to implement such SMS sending/receiving functionalities in GUI-less Exe (Server).


  • Create one GUI-less exe project( for e.g: SMSByExe ) from Application Wizard. Generally it is termed as Console-based Exe project in the Application Wizard.
  • Download SmsHandler.zip as follows:
  • Extracting SmsHandler.zip will result into SmsHandler.h and SmsHandler.cpp
  • Copy-Paste SmsHandler.h into your project's /inc folder.
  • Copy-Paste SmsHandler.cpp into your project's /src folder.
  • Edit your .mmp file. Add an entry for SmsHandler.cpp in SOURCE directive.
SOURCE	SMSHandler.cpp
  • Edit your .mmp file. Add libraries for SMS handling, and capabilities required.
//Libraries included for SMS support-
LIBRARY msgs.lib smcm.lib gsmu.lib mtur.lib
CAPABILITY ReadUserData WriteUserData NetworkServices

Sending message


#ifndef __SMSBYEXE_H__
#define __SMSBYEXE_H__
// Include Files
#include <e32base.h>
class CSmsHandler; //forward declaration
// Function Prototypes
GLDEF_C TInt E32Main();
LOCAL_C void SendSMSL();
CSmsHandler* iSmsHandler;
#endif // __SMSBYEXE_H__
  • Open your SMSByExe.cpp file.
  • Include SmsHandler.h.
#include "SMSHandler.h" //Added for SMS Handling


The following code snippet illustrates how to initialize SMSHandler class.

//  Include Files  
#include "SmsByExe.h"
#include <e32base.h>
#include <e32std.h>
#include "SMSHandler.h"
// Local Functions
LOCAL_C void MainL()
// add your program code here, example code below
//This is for initializing SMSHandler
iSmsHandler = CSmsHandler::NewL();
LOCAL_C void DoStartL()
// Create active scheduler (to run active objects)
CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
// Delete active scheduler
LOCAL_C void SendSMSL()
TBuf<128> SMSText,PhoneNumber;
SMSText.Copy(_L("SMS By An EXE"));
// Replace the number you wish to send message
iSmsHandler->SendL( PhoneNumber, SMSText) ;
// Global Functions
GLDEF_C TInt E32Main()
// Create cleanup stack
CTrapCleanup* cleanup = CTrapCleanup::New();
// Run application code inside TRAP harness, wait keypress when terminated
TRAPD(mainError, DoStartL());
delete cleanup;
return KErrNone;

Receiving Message

  • Open your SmsHandler.cpp file which is supplied from the .zip file.


void CSmsHandler::MessageReceivedL( TMsvId aEntryId )
CMsvEntry* serverEntry = iSession->GetEntryL( aEntryId ); // current entry
CleanupStack::PushL( serverEntry );
TMsvEntry entry = serverEntry->Entry(); // currently handled message entry
entry.SetNew( ETrue );
entry.SetUnread( ETrue );
entry.SetVisible( ETrue );
serverEntry->ChangeL( entry ); // commit changes
//Added to retrieve message body
// iDescription will have only first 32 characters from the message
const TDesC& descp = entry.iDescription;
TBuf8<40> MessageArrived;
//Added to retrieve Phone Number of the Sender
CSmsHeader& header = iSmsMtm->SmsHeader();
TPtrC from = header.FromAddress();
const TDesC& phoneNumber = from;
CleanupStack::PopAndDestroy( serverEntry );

Related Links:

This page was last modified on 18 September 2012, at 05:57.
55 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.