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

Reply
New Developer
badgrant
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);

Please use plain text.
Developer
sandeepkumar03
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.

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800698/How_To_...

 

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.

 

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&thread.id=38241

 

Thanks,

Sandeep

 

------------------------

 

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

Please use plain text.
New Developer
badgrant
Posts: 2
Registered: ‎05-25-2009
My Device: Not Specified

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

Many thanks!
Please use plain text.