Troubleshooting guide
157
10: Using the messages application
Reply to a message
Add the recipients. 1. Invoke Message.addRecipients() and provide the type of recipient (TO, CC, or BCC) and
the array of addresses to add as parameters to the method. If the message has multiple types of
recipients, invoke
addRecipients() once for each recipient type.
msg.addRecipients(Message.RecipientType.TO, toList);
Specify the name and email address of
the sender.
>Invoke setFrom(Address).
Address from = new Address("scott.mcpherson@blackberry.com", "Scott
McPherson");
msg.setFrom(from);
Add a subject line. >Invoke setSubject(String).
msg.setSubject("Test Message");
Specify the message contents. >Invoke setContent(String). Typically, the application retrieves content from text that a
BlackBerry® device user types in a field.
try {
msg.setContent("This is a test message.");
} catch(MessagingException e) {
System.out.println(e.getMessage());
}
Send the message. >Invoke Transport.send(Message). The Transport object represents the messaging
transport protocol.
try {
Transport.send(msg);
} catch(MessagingException e) {
System.out.println(e.getMessage());
}
Task Steps
Reply to a message. >Invoke Message.reply(Boolean). As a parameter to this method, specify true to reply to all
message recipients or false to reply to only the sender.
Store store = Session.waitForDefaultSession().getStore();
Folder[] folders = store.list(INBOX);
Folder inbox = folders[0];
Message[] messages = folder.getMessages();
if( messages.length > 0 ) {
Message msg = messages[0];
}
Message reply = msg.reply(true);
Transport.send(reply);
Task Steps