Reply to a message

  1. Import the required classes and interfaces.
    import net.rim.blackberry.api.mail.Folder;
    import net.rim.blackberry.api.mail.Message;
    import net.rim.blackberry.api.mail.Session;
    import net.rim.blackberry.api.mail.Store;
    import net.rim.blackberry.api.mail.Transport;
    
  2. Invoke Session.getTransport() and store the returned object in a variable of type Transport. The Transport object represents the messaging transport protocol.
    Transport trans = Session.getTransport();
  3. Invoke Session.waitForDefaultSession().getStore() to retrieve the Store object.
    Store store = Session.waitForDefaultSession().getStore();
  4. Invoke Store.list(INBOX) to retrieve all the folders in the INBOX folder. Store the folders in a Folder array.
    Folder[] folders = store.list(INBOX);
  5. Specify a specific array element to retrieve the inbox folder.
    Folder inbox = folders[0];
  6. Invoke Folder.getMessages() to retrieve the messages in the inbox folder. Store the messages in a Message array.
    Message[] messages = inbox.getMessages();
  7. Invoke Message.reply(Boolean) and specify true to reply to all message recipients or false to reply to only the sender.
    if( messages.length > 0 ) 
    {
       Message msg = messages[0];
    }
    Message reply = msg.reply(true);
  8. Invoke Transport.send(Message) to send the reply.
    try 
    {
       trans.send(reply);
    } 
    catch(MessagingException e) 
    {
       System.out.println(e.getMessage());
    }
    
Next topic: Forward a message
Previous topic: Send a message

Was this information helpful? Send us your comments.