×
Namespaces

Variants
Actions

Sending an SMS message using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd Edition
S60 5th Edition
Article
Keywords: RSendAs, RSendAsMessage
Created: tepaa (29 Apr 2009)
Last edited: hamishwillee (13 Jun 2012)

Contents

Overview

This snippet demonstrates how to send an SMS message with RSendAs from sendas2.lib.

Note: The current implementation of RSendAs uses the default values for settings (which can not really be changed) and the message body is converted to the 7-bit-sms format. All characters that are not defined in the 7-bit-sms format will be replaced with question marks.


MMP file

The following libraries and capabilities are required:

CAPABILITY None
LIBRARY sendas2.lib

Header file

#include <rsendas.h>        // RSendAs
#include <rsendasmessage.h> // RSendAsMessage
#include <smut.h> // KUidMsgTypeSMS
#include <e32base.h>
 
class CYourSmsSender : public CBase
{
public:
static CYourSmsSender* NewLC();
virtual ~CYourSmsSender();
 
public:
void SendSmsL(const TDesC& aAddr, const TDesC& aMsg);
 
private:
void ConstructL();
CYourSmsSender();
 
private:
RSendAs iSendAs;
};


Source file

CYourSmsSender* CYourSmsSender::NewLC()
{
CYourSmsSender* self = new (ELeave) CYourSmsSender();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
 
void CYourSmsSender::ConstructL()
{
User::LeaveIfError(iSendAs.Connect());
}
 
CYourSmsSender::~CYourSmsSender()
{
iSendAs.Close();
}
 
// Send SMS message
void CYourSmsSender::SendSmsL(const TDesC& aAddr, const TDesC& aMsg)
{
// Create message
RSendAsMessage message;
message.CreateL(iSendAs, KUidMsgTypeSMS);
CleanupClosePushL(message);
 
// Prepare the message
message.AddRecipientL(aAddr, RSendAsMessage::ESendAsRecipientTo);
message.SetBodyTextL(aMsg);
 
// Send the message
TRequestStatus status;
message.SendMessage(status);
User::WaitForRequest(status);
message.Close();
 
CleanupStack::Pop(); // message
}


How to use

HBufC* message = HBufC::NewLC(60);
message->Des().Append(_L("hello world!"));
 
iYourSmsSender->SendSmsL(_L("12345678"),*message);
 
CleanupStack::PopAndDestroy(); //message


Postconditions

An SMS message is sent.

This page was last modified on 13 June 2012, at 09:57.
46 page views in the last 30 days.
×