Create Local SMS
Article Metadata
Using the following code an SMS can be created in the local Inbox. The user gets a new message with the SMS alert tone (if profile not silent). SMS does not use network services ,its just created locally. This example needs intialization and setup of some MTM related classes which is not mention here, please refer here to get more information about it
void CMobloggerPhotoEngine::SMS2Inbox()
{
iSendingSms=ETrue;
TBuf<10> aAddress(_L("Nokia"));
TBuf<20> aDescription(_L("Important Message"));
_LIT(KTxt1,"Hi phone owner, how r u?");
TBuf<150> iMessage;
iMessage.Copy(KTxt1);
iMtmRegistry = CClientMtmRegistry::NewL(*iSession);
iSmsMtm = STATIC_CAST( CSmsClientMtm*, iMtmRegistry->NewMtmL(KUidMsgTypeSMS));
iSmsMtm->SwitchCurrentEntryL(KMsvGlobalInBoxIndexEntryId); //inbox
iSmsMtm->CreateMessageL(KUidMsgTypeSMS.iUid);
CSmsHeader& iHeader = iSmsMtm->SmsHeader();
iHeader.SetFromAddressL(aAddress);
CRichText& body = iSmsMtm->Body();
body.Reset();
body.InsertL(0, iMessage);
TMsvEntry entry = iSmsMtm->Entry().Entry();
entry.SetInPreparation(EFalse);
entry.SetVisible(ETrue);
entry.iDate.HomeTime();
entry.iDescription.Set(aDescription);
entry.iDetails.Set(aAddress);
entry.SetUnread(ETrue);
iSmsMtm->Entry().ChangeL(entry);
iSmsMtm->SaveMessageL();
}
the following are the header files required
#include <msvapi.h>
#include <mtclreg.h>
#include <SMSCLNT.h>
#include <msvstd.h>
#include <smut.h>
#include <txtrich.h>
#include <SMUTHDR.h>
LIBRARY msgs.lib smcm.lib gsmu.lib


03 Sep
2009
The code snippet demonstrates on how an SMS can be created in the local Inbox. SMS does not use external network services and hence user is not charged for this. However, for the user it might seem to be just another SMS from someone else. The function can be implemented directly by including the required header and library files.