Samsung Electronics logo

Managing Conversations



To create engaging applications with various messaging features, you must learn to load email messages and attachments and synchronize email:

  1. Retrieve the messaging service using the getMessageServices() method.

    webapis.messaging.getMessageServices("messaging.email", serviceListCB, errorCallback);
  2. Search for all email messages with attachments using the findMessages() method of the MessageStorage interface:

    service.messageStorage.findMessages(new webapis.AttributeFilter("hasAttachment", "EXACTLY", true), 
                                        messageQueryCallback);
  3. To load a message body, use the loadMessageBody() method of the MessageService interface:

    /* Success callback for the search operation */
    function messageQueryCallback(messages) 
    {
       for (var i = 0; i < messages.length; i++) 
       {
          var message = messages[i];
          if (!message.body.loaded) 
          {
             webapis.messaging.loadMessageBody(message, successCallback, errorCallback);
    
  4. To download the message attachments, use the loadMessageAttachment() method with an array of attachments (with valid file paths) as a parameter:

             webapis.messaging.loadMessageAttachment(message.attachments[0], successCallback,
                                                   errorCallback);
          }
       }
    }
  5. To synchronize email with an external server:

    1. To synchronize all account folders, use the sync() method:

      /* Sync the folders in the success event handler */
      function servicesListSuccessCB(services) 
      { 
         services[0].sync(serviceSynced, null, 30); 
      }
      
      /* Get the email service */
      webapis.messaging.getMessageServices("messaging.email", servicesListSuccessCB); 
    2. To synchronize a specific folder, use the syncFolder() method. In the following example, only folders containing "INBOX" in their name are synchronized.

      var emailService; /* Assume email service is initialized */
      function serviceCallback(services) 
      {
         emailService = services[0]; 
      }
      
      /* Synchronize in the search success event handler */
      function folderQueryCallback(folders) 
      {
         console.log(folders.length + " folders(s) found!"); 
         for (var i=0; i<folders.length; i++) 
         { 
            emailService.syncFolder (folders[i], folderSynced, null, 30); 
         }
      }; 
      
      /* Get the email service */
      webapis.messaging.getMessageServices("messaging.email", serviceCallback, errorCallback); 
      
      /* Search for specific folders */
      var filter = new webapis.AttributeFilter("name", "CONTAINS", "INBOX"); 
      emailService.messageStorage.findFolders(filter, folderQueryCallback));