Help Center
Local Navigation
- Integrating with BlackBerry Device Software applications
- Message list
- Create a new blank SMS text message
- Create a new populated text message
- Create a new blank MMS message
- Create a new blank email message
- Create a new populated email message
- Create a new blank PIN message
- Create a new populated PIN message
- Receive a message notification
- Add a listener to the message store
- Add a listener to the message store for batch updates
- Add a listener to a folder
- Retrieve the total count of unread email messages in all folders in the store
- Open a message
- Retrieving the body of an email message
- Notify a BlackBerry device application that an email message is about to be sent
- Notify a BlackBerry device application that an MMS message is about to be sent
- Notify a BlackBerry device application that an SMS message is about to be sent
- Send a message
- Reply to a message
- Forward a message
- Work with message folders
- Attachments
- Calendar
- Contact list
- Task list
- Phone
- BlackBerry Browser
- Menu items
- Glossary
- Provide feedback
- Document revision history
- Legal notice
BlackBerry Manuals & Help
>
Developer Documentation
>
Java Development Guides and API Reference
>
Development Guide
Integration - BlackBerry Java Application - 5.0
Send a message
- Import the required classes and interfaces.
import net.rim.blackberry.api.mail.Address; import net.rim.blackberry.api.mail.AddressException; import net.rim.blackberry.api.mail.Folder; 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.Store; import net.rim.blackberry.api.mail.Transport;
- Declare a Message object.
Message msg;
- 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]; msg = new Message(sentfolder);
- Create an array of Address objects.
Address toList[] = new Address[1];
- In a try block, add each address to the array.
try { toList[0]= new Address("ming.li@example.com", "Ming Li"); } - In a catch block, manage a AddressException, which is thrown if an address is invalid.
catch(AddressException e) { System.out.println(e.toString()); } - 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 Message.addRecipients() once for each recipient type.
msg.addRecipients(Message.RecipientType.TO, toList);
- Invoke Message.setFrom(Address).
Address from = new Address("ming.li@example.com", "Ming Li"); msg.setFrom(from); - Invoke Message.setSubject(String).
msg.setSubject("Test Message"); - Invoke Message.setContent(String). (Typically, the BlackBerry® device 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()); } - 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();
- Invoke Transport.send(Message) to send the message.
try { trans.send(msg); } catch(MessagingException e) { System.out.println(e.getMessage()); }
Next topic: Reply to a message