Forward a message

  1. Import the required classes and interfaces.
    import net.rim.blackberry.api.mail.Address;
    import net.rim.blackberry.api.mail.Message;
    import net.rim.blackberry.api.mail.MessagingException;
    import net.rim.blackberry.api.mail.Session;
    import net.rim.blackberry.api.mail.Transport;
    
  2. Invoke Message.forward() on an existing Message object. The subject line of a forwarded message is set automatically to FW:original_subject.
    Message fwdmsg = msg.forward();
  3. Create an array of addresses.
    Address toList[] = new Address[1];
  4. Add a new Address object to the array.
    toList[0]= new Address("ming.li@example.com", "Ming Li");
    
  5. Invoke Message.addRecipients(int, Address[]) to add recipients to the Message.
    fwdmsg.addRecipients(Message.RecipientType.TO, toList);
  6. Invoke Message,setContent(String) to set the content of the message that appears before the original message.
    try 
    {
       fwdmsg.setContent("This is a forwarded message.");
    } 
    catch(MessagingException e) 
    {
       System.out.println(e.getMessage());
    }
  7. 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();
  8. Invoke Transport.send(Message).
    try 
    {
       trans.send(fwdmsg);
    } 
    catch(MessagingException e) 
    {
       System.out.println(e.getMessage());
    }
Previous topic: Reply to a message

Was this information helpful? Send us your comments.