Troubleshooting guide
156
BlackBerry Java Development Environment Development Guide
Store store = Session.waitForDefaultSession.getStore();
Folder folder = Store.getFolder("SampleFolder");
2. Retrieve the message objects from the folder. Iterate through the array and retrieve information, such as the
sender and subject, to display to the BlackBerry® device user.
Message[] msgs = folder.getMessages();
3. When a BlackBerry device user selects a message from the list, invoke methods on the Message object to
retrieve the appropriate fields and body contents to display to the BlackBerry device user.
Message msg = msgs[0]; // Retrieve the first message.
Address[] recipients = msg.getRecipients(Message.RecipientType.TO)
Date sent = msg.getSentDate();
Address from = msg.getFrom();
String subject = msg.getSubject();
Object o = msg.getContent();
// Verify that the message is not multipart.
if ( o instanceof String ) {
String body = (String)o;} //...
4. Invoke getBodyText() on a message to retrieve the plain text contents as a String. If the message does
not contain plain text, the method returns null.
Send a message
Task Steps
Create a message. 1. Create a Message object.
2. Specify a folder in which to save a copy of the sent message.
Store store = Session.getDefaultInstance().getStore();
Folder[] folders = store.list(Folder.SENT);
Folder sentfolder = folders[0];
Message msg = new Message(sentfolder);
Specify the recipients. 1. Create an array of Address objects.
Address[] toList = new Address[1];
2. Add each address to the array.
3. Create code to catch an AddressException that the Address array throws if an address is
invalid.
try {
toList[0]= new Address("aisha.wahl@blackberry.com", "Aisha Wahl");
} catch(AddressException e) {
System.out.println(e.toString());
}