网上找到的源码,先做备份。下次肯定会用到~
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);