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 MMS messages in Symbian Web Runtime

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



This code snippet shows how to send MMS messages synchronously and asynchronously and attach images to messages using the Messaging and Media Management Platform Services for S60 Web Runtime introduced in S60 5th Edition.

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

To obtain access to the service object for the Media Management Service API, the device.getServiceObject("Service.MediaManagement", "IDataSource") method is used.


<?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 />
<label for="fileList">Attachments:</label><br />
<select size="5" id="fileList" multiple></select><br />
<input type="button" value="Send" onclick="sendMMS();" />

Source: sendMessage.js

var messagingServiceObj = null;
var multimediaServiceObject = null;
window.onload = init;
// Initializes the widget
function init() {
try {
messagingServiceObj =
device.getServiceObject("Service.Messaging", "IMessaging");
multimediaServiceObject =
device.getServiceObject("Service.MediaManagement", "IDataSource");
//Setting the criteria for fetching images
var criteria = new Object();
criteria.Type = "FileInfo";
criteria.Filter = new Object();
criteria.Filter.FileType = "Image";
criteria.Sort = new Object();
criteria.Sort.Key = "FileSize";
result =
multimediaServiceObject.IDataSource.GetList(criteria, callback);
} catch (ex) {
alert("Error in initializing the widget");
* A callback function used to handle results of fetching multimedia files.
* @param transId A number representing the transaction that called the
* callback
* @param eventCode A number representing the callback return status
* @param result An object for holding the callback return value

function callback(transId, eventCode, result) {
if(result.ErrorCode != 0) {
alert("Error in creating file list:" + result.ErrorCode);
* Creates a list item for every multimedia file in "iterator".
* @param iterator The list of files

function createFileList(iterator) {
var fileList = document.getElementById("fileList");
//Reset to set pointer to the first element.
var item;
//Cleaning the file list.
while (fileList.length != 0) {
while ((item = iterator.getNext()) != undefined) {
var node = document.createElement("option");
//Value of option consists of the full path.
node.value = item.FileNameAndPath;
node.appendChild(document.createTextNode(item.FileName +
function sendMMS() {
var criteria = new Object();
//Setting the type of the message
criteria.MessageType = "MMS";
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");
var fileList = document.getElementById("fileList");
//Adding the selected items as attachments of the message
for (var i = 0; i < fileList.options.length; i++) {
if (fileList.options[i].selected) {
criteria.Attachment = fileList.options[i].value;
try {
if (document.getElementById("async").checked == false) {
//Send the message synchronously
var result = messagingServiceObj.IMessaging.Send(criteria);
} else {
//Send the message asynchronously
messagingServiceObj.IMessaging.Send(criteria, onSendDone);
} catch(exception) {
alert("SendMMS error: " + exception);
// Called when asynchronous message sending has been 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 MMS synchronously or asynchronously (check box).
  • Text fields are used to define the receiver's phone number and message contents.
  • The user can select the files to attach. A list box shows all files that can be selected.
  • The message is sent by pressing "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 mms messages in

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