How to send an SMS using sockets
This code will help to sending sms via a socket and you can send it via exe or an app also. Its very simple.
Article Metadata
Compatibility
Platform(s): Symbian (all)
Platform Security
Signing Required: Self-Signed
Capabilities: NetworkServices.
Article
Created: kkrish
(14 May 2007)
Last edited: hamishwillee
(13 Sep 2011)
Headers required:
#include <es_sock.h> //RSocketServ,RSocket
#include <smsuaddr.h> //TSmsAddr
#include <f32file.h> //RFs
#include <gsmuset.h> //TSmsUserDataSettings
#include <Gsmumsg.h> //CSmsMessage
Library Needed:
LIBRARY esock.lib //RSocketServ, RSocket
LIBRARY smsu.lib //TSmsAddr
LIBRARY efsrv.lib //RFs
LIBRARY gsmu.lib //TSmsUserDataSettings
Source:
RSocketServ sockServ;
User::LeaveIfError(sockServ.Connect());
CleanupClosePushL(sockServ);
RSocket socket;
User::LeaveIfError(
socket.Open(sockServ, KSMSAddrFamily, KSockDatagram, KSMSDatagramProtocol));
CleanupClosePushL(socket);
TSmsAddr smsaddr;
smsaddr.SetSmsAddrFamily(ESmsAddrSendOnly);
smsaddr.SetPort(smsaddr.Port() + 1);
User::LeaveIfError(socket.Bind(smsaddr));
RFs fileSession;
User::LeaveIfError(fileSession.Connect());
CleanupClosePushL(fileSession);
CSmsBufferBase *buffer = CSmsBuffer::NewL();
CleanupStack::PushL(buffer);
buffer->InsertL(0, _L("This is a test Message"));
TSmsUserDataSettings smsSettings;
smsSettings.SetAlphabet (TSmsDataCodingScheme::ESmsAlphabet8Bit);
smsSettings.SetTextCompressed(EFalse);
CSmsMessage *cSmsMessage = CSmsMessage::NewL(
fileSession, CSmsPDU::ESmsSubmit, buffer);
CleanupStack::Pop(buffer);
CleanupStack::PushL(cSmsMessage);
cSmsMessage->SetUserDataSettingsL(smsSettings);
cSmsMessage->SetToFromAddressL(_L("98888888888888"));
cSmsMessage->SmsPDU().SetServiceCenterAddressL(_L("+9999999"));
RSmsSocketWriteStream writestream(socket);
writestream << *cSmsMessage;
writestream.CommitL();
TRequestStatus status;
TPckgBuf<TUint> sendBuffer;
socket.Ioctl(KIoctlSendSmsMessage, status, &sendBuffer, KSolSmsProv);
User::WaitForRequest(status);
CleanupStack::PopAndDestroy(cSmsMessage);
CleanupStack::PopAndDestroy(&fileSession);
CleanupStack::PopAndDestroy(&socket);
CleanupStack::PopAndDestroy(&sockServ);


Hi,
I got a query ? Will this SMS charged by the Operator?
Its from users perspective iam asking.
Regards, Pavan
Ta-X -
can any1 help me with the source file of the project above ,am find it hard to understand it..send it to xdlova870@gmail.com ..if any1 can ...thnk uTa-X 16:44, 9 September 2011 (EEST)
Hamishwillee - Ta-X - suggest community discussion boards
Hi Ta-X
I suggest you ask your questions on the Symbian C++ discussion boards - its fairly straightforward code but if you don't know Symbian C++ I can understand why you might be confused.. The article was written in 2007 so its likely the author won't respond.
Regards
Hamishhamishwillee 04:24, 13 September 2011 (EEST)