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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

New Developer
Posts: 2
Registered: ‎05-25-2009
My Device: Not Specified

How to add files as attachment to email and MMS programmatically?

I'm very very very new to BB java development and need to have this task urgently done.


I've successfully sent texted-based emails and MMS, but have difficulties to send them with attachments. Let's say, I took a photo named example.jpg, stored at default location store/home/user/pictures/... I wish to send it with an email and with MMS. How do I add it to the msg object and sent it along. Thank you!


Here is my code I've done so far.:


Store store = Session.getDefaultInstance().getStore(); //Get the Store from the default mail Session. Folder[] folders = store.list(Folder.SENT); //retrieve the sent folder Folder sentfolder = folders[0]; Message msg = new Message(sentfolder); msg.addRecipients(Message.RecipientType.TO, addresses); msg.setSubject("Bla Bla Bla"); msg.setContent(body);


And for MMS:


// opens connection MessageConnection conn = (MessageConnection) Connector.open(addr); // prepares multipart message MultipartMessage msg = (MultipartMessage)conn.newMessage(MessageConnection.MULTIPART_MESSAGE); //set message msg.setAddress(addr); msg.setSubject(subject); //set parts byte[] bodyBin = body.getBytes(MMS_TEXT_ENC); MessagePart bodyPart = new MessagePart(bodyBin, 0, bodyBin.length, "text/plain", "id1", "contentLocation", MMS_TEXT_ENC); msg.addMessagePart(bodyPart);

Posts: 117
Registered: ‎02-12-2009
My Device: Not Specified

Re: How to add files as attachment to email and MMS programmatically?

Hi Badgrant,


For attachment for emails, check following link. Also if you do a search you will find some threads regarding this.




And note that image attachments will not work on Simulator with ESS. Only text would be sent as per my experience. I have tried on device with BIS and attachments works fine on device.


For MMS, even i was trying for MMS but still no luck. I was not even able to send text. Only Subject is visible on recepient's handset. You can check following thread.









If your problem gets solved, please mark the thread as "Accepted Solution". And click on Kudos to thank the user who helps you.

New Developer
Posts: 2
Registered: ‎05-25-2009
My Device: Not Specified

Re: How to add files as attachment to email and MMS programmatically?

Many thanks!