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

New Developer
Posts: 5
Registered: ‎05-10-2009
My Device: Not Specified

How to embed multipart/alternative in multipart/mixed

[ Edited ]

I'm having a problem understanding how I might implement the RFC 2046 concept of embedding multiparts within multiparts.


For example, I would like to build a multipart message that contains both alternative message formatting and file attachments.  If I read the RFC 2046 correctly I would do this by declaring a multipart/mixed, containing a multipart/alternative (with Content-Types of text/plain and text/html, for example) and a Content-Type of say application/x-zip-compressed for the file attachment.


I'm able to do one or the other - multipart/mixed or multipart/alternative, and they work great.  But no luck determining how to do both. 


Thanks, in advance.


Blackberry 8100 and 8120

JDE version


Here is one try that doesn't work:


                String fileData = "<html>just a simple test</html/";
                String messageData = "Mail Attachment Demo";
                Multipart mpMixed = new Multipart("mixed");
                Multipart mpAlternative = new Multipart("alternative");
                TextBodyPart tbp1 = new TextBodyPart(mpAlternative, messageData);
                TextBodyPart tbp2 = new TextBodyPart(mpAlternative, messageData);
                SupportedAttachmentPart sap = new SupportedAttachmentPart(mpMixed, "text/html", "file.html", fileData.getBytes());
                msg.writeTo(System.out );

Message Edited by bborup on 08-02-2009 10:57 AM
New Developer
Posts: 5
Registered: ‎05-10-2009
My Device: Not Specified

Re: How to embed multipart/alternative in multipart/mixed

Let me try another example.  In other environments I can do this:


   // parent multipart (mixed)
   MimeMultipart mixedPart = new MimeMultipart("mixed");
   // child alternative html/text multipart
   MimeMultipart alternativeMultiPart = new MimeMultipart( "alternative");
   BodyPart alternativeBodyPart = new MimeBodyPart();
   // set the text
   alternativeBodyPart.setText("text only version");
   // set the html
   alternativeBodyPart = new MimeBodyPart();
   alternativeBodyPart.setContent( "<h1>HTML</h1><strong>only</strong> version", "text/html");
   // set the content in the mixed part
   alternativeBodyPart = new MimeBodyPart();
   // attach the file
   BodyPart mixedBodyPart = new MimeBodyPart();
   String filename = "C:\test.gif";
   mixedBodyPart = new MimeBodyPart();
   DataSource source = new FileDataSource(filename);
   mixedBodyPart.setDataHandler(new DataHandler(source));
   // set the content in the message
Please note that the "alternativeBodyPart", or "alternativeMultiPart", is added to the "mixedPart".


How can I accomplish this in the Blackberry world?




Regular Contributor
Posts: 73
Registered: ‎12-30-2011
My Device: All devices
My Carrier: RIM

Re: How to embed multipart/alternative in multipart/mixed

Please i want to do same, if u have proper solution code please post it


Mohd Farhan