Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Sending SMS messages in Symbian Web Runtime

From Wiki
Jump to: navigation, search
Article Metadata
Code ExampleCompatibility
Platform(s): S60 5th Edition and later
S60 5th Edition
Keywords: device.getServiceObject(), Service.Messaging.Send()
Created: ivruban (10 Dec 2008)
Last edited: hamishwillee (14 Jun 2013)



This code snippet shows how to send SMS messages synchronously and asynchronously using the Messaging Platform Service for Symbian Web Runtime.

To obtain access to the service object for the Messaging Service API, the device.getServiceObject("Service.Messaging", "IMessaging") method is used.

After setting the correct values for the message type (criteria.MessageType), recipient (criteria.To), and body text of the message (criteria.BodyText), the IMessaging.Send(criteria) method is used to send the SMS.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="sendMessage.js" />
<div id="bodyContent" class="bodyContent">
<input type="checkbox" id="async" />
<label for="async">Send asynchronously</label><br />
<label for="phoneNumber">Phone number:</label><br />
<input type="text" id="phoneNumber" size="12" maxlength="12" />
<br />
<label for="message">Message:</label><br />
<textarea id="message" cols="40" rows="3"></textarea><br />
<input type="button" value="Send" onclick="sendSMS();" />

Source: sendMessage.js

var serviceObj = null;
window.onload = init;
// Initializes the widget
function init() {
// Obtain the service object
try {
serviceObj = device.getServiceObject("Service.Messaging",
} catch (ex) {
alert("Service object cannot be found.");
function sendSMS() {
var criteria = new Object();
//Setting the type of the message
criteria.MessageType = "SMS";
var phoneNumber = document.getElementById("phoneNumber").value;
if (phoneNumber != null) {
//Setting the "To" field of the message, can't be empty
criteria.To = phoneNumber;
} else {
alert("Phone number is empty");
var messageText = document.getElementById("message").value;
if (messageText != null) {
//Setting the body text field of the message, can't be empty
criteria.BodyText = messageText;
} else {
alert("Text is empty");
try {
if (document.getElementById("async").checked == false) {
//Send the message synchronously
var result = serviceObj.IMessaging.Send(criteria);
} else {
//Send the message asynchronously
serviceObj.IMessaging.Send(criteria, onSendDone);
} catch(exception) {
alert("SendSMS error: " + exception);
// Called when asynchronous message sending has completed
function onSendDone(transId, eventCode, result) {
function checkError(error) {
if (error.ErrorCode != 0) {
alert("Error in sending message");
} else {
alert("Message was sent succesfully");


  • When the snippet is started, the user can choose to send the SMS synchronously or asynchronously (check box).
  • Input field is used to define the receiver's phone number.
  • To send the message press "Send".

Supplementary material

You can view the source file and the executable application in the attached ZIP archive. The archive is available for download at Media:Sending sms messages in

This page was last modified on 14 June 2013, at 06:34.
58 page views in the last 30 days.