Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Create and send messages

by BlackBerry Development Advisor ‎02-16-2010 01:17 PM - edited ‎02-17-2010 03:59 PM (3,887 Views)

Summary


This article applies to the following:

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


Description


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@company.com”, “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
msg.setPriority(Message.Priority.HIGH);

//send the message
Transport.send(msg);
}
catch (Exception me) {
System.err.println(me);
}



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

 



Contributors