Codementor Events

JavaMail Multiparts

Published Aug 15, 2017Last updated Aug 26, 2017
JavaMail Multiparts

Why the need to handle Multiparts of Mail differently ??

Basically there are many Multipart types and they all need to handled uniquely:

Mixed Subtype

The "mixed" subtype of "multipart" is intended for use when the body parts are independent and need to be bundled in a particular order. Any "multipart" subtypes that an implementation does not recognize must be treated as being of subtype "mixed".

Alternative Subtype

The "multipart/alternative" type is syntactically identical to "multipart/mixed", but the semantics are different. In particular, each of the body parts is an "alternative" version of the same information.

Systems should recognize that the content of the various parts are interchangeable. Systems should choose the "best" type based on the local environment and references, in some cases even through user interaction. As with "multipart/mixed", the order of body parts is significant. In this case, the alternatives appear in an order of increasing faithfulness to the original content.

In general, the best choice is the LAST part of a type supported by the recipient system's local environment.

"Multipart/alternative" may be used, for example, to send a message in a fancy text format in such a way that it can easily be displayed anywhere:

From: Nathaniel Borenstein <nsb@bellcore.com>
 To: Ned Freed <ned@innosoft.com>
 Date: Mon, 22 Mar 1993 09:41:09 -0800 (PST)
 Subject: Formatted text mail
 MIME-Version: 1.0
 Content-Type: multipart/alternative; boundary=boundary42

 --boundary42
 Content-Type: text/plain; charset=us-ascii

   ... plain text version of message goes here ...

 --boundary42
 Content-Type: text/enriched

   ... RFC 1896 text/enriched version of same message
       goes here ...

 --boundary42
 Content-Type: application/x-whatever

   ... fanciest version of same message goes here ...

 --boundary42--

In this example, users whose mail systems understood the "application/x-whatever" format would see only the fancy version, while other users would see only the enriched or plain text version, depending on the capabilities of their system.

Discover and read more posts from Sushant Saurabh
get started
post commentsBe the first to share your opinion
Show more replies