Create and send messages

by Retired ‎02-16-2010 01:17 PM - edited ‎02-17-2010 03:59 PM (4,251 Views)


This article applies to the following:

  • BlackBerry® smartphones based on Java® technology
  • BlackBerry® Device Software 4.0 and later


The following code fragment outlines how to programmatically send a message while setting some additional parameters prior to sending:

Package used is net.rim.blackberry.api.mail

//Get the Store from the default mail Session.
Store store = Session.getDefaultInstance().getStore();

//retrieve the sent folder
Folder[] folders = store.list(Folder.SENT);
Folder sentfolder = folders[0];

//create a new message and store it in the sent folder
Message msg = new Message(sentfolder);
Address recipients[] = new Address[1];

try {
recipients[0]= new Address(“”, “user”);

//add the recipient list to the message
msg.addRecipients(Message.RecipientType.TO, recipients);

//set a subject for the message
msg.setSubject(“Test email”);

//sets the body of the message
msg.setContent(“This is a test email from my BlackBerry Wireless Handheld”);

//sets priority

//send the message
catch (Exception me) {

To add an attachment to a message, see this article.