Here's a working example of creating a new email and bringing it up for review before sending it from my project BBSSH. The dialog/popup you would not need and could delete. In this example we're taking a bitmap as an argument, and converting it to a PNG which we attach to the email. Different content type would be attached similarly.
You should be able to do just about anything from the simulator if the code is unsigned; however I think that emails won't actually get sent since the simulator itself has no connection to an actual mail server.
/**
* Sends feedback, optionally including the provided bitmap as an attachement.
*
* it is the caller's responsibility to ensure that this is invoked
* in a properly synchronized manner.
*
* @param screenshot - if not null, this function prompts
* the user to include the screenshot as an attachment.
*/
public static void sendFeedback(Bitmap screenshot) {
ResourceBundle b = ResourceBundle.getBundle(BBSSHRResource.BUNDLE_ID,
BBSSHRResource.BUNDLE_NAME);
try {
Multipart mp = new Multipart();
Message msg = new Message();
Address[] addresses = {new Address("[email protected]", "Recipient Name")};
if (screenshot == null || Dialog.ask(Dialog.D_YES_NO,
b.getString(BBSSHRResource.MSG_FEEDBACK_INCLUDE_SCREENSHOT), Dialog.YES) == Dialog.NO) {
} else {
PNGEncodedImage img = PNGEncodedImage.encode(screenshot);
SupportedAttachmentPart pt = new SupportedAttachmentPart(mp, img.getMIMEType(),
"bbssh-screen.png", img.getData());
mp.addBodyPart(pt);
msg.setContent(mp);
}
msg.addRecipients(RecipientType.TO, addresses);
msg.setSubject("BBSSH Feedback");
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(msg));
} catch (AddressException ex) {
Logger.getLogger().log(10, "Unable to send feedback: " + ex.getMessage());
} catch (MessagingException ex) {
Logger.getLogger().log(10, "Unable to send feedback: " + ex.getMessage());
}
}
If you wanted to send the message instead of bringing it up for review instead of Invoke.invokeApplication you would use Transport.send(msg);