How to send an email from your BlackBerry application
One of the main reasons for the BlackBerry to become so popular was their excellent email service and RIM was the pioneer of introducing Push email system where the user will be notified immediately once the email is received by the email server. In your BlackBerry application also you can explore the power of BlackBerry email service quite easily.
The following code fragment outlines how to programmatically send a message while setting some additional parameters prior to sending:
//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.printIn(me);
}
How to test the email functionality using ESS (Email Server Simulator)
ESS should be used if the email functinality is being tested in the BlackBerry simulator. If you want test a simple email with a message and simple text attachment ESS would be sufficient. But if you need to test a email with image attchment I would recommend you to use a real BlackBerry device since ESS does not support image attachments to be sent.
See this for the setting up of ESS environment.



