Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multipart/alternative subtype, when client use it?

Why webmails (like Gmail) sends MIME messages using multipart/alternative subtype (when composing in HTML) while others send HTML as MIME with text/html parts inside (without using alternative subtype)?

like image 279
gremo Avatar asked Nov 30 '11 01:11

gremo


2 Answers

The section 5.1.4 of RFC 2046 defines multipart/alternative MIME type to allow the sender to provide different, interchangeable representations of the same message and to leave it up to the receiver to chose the form of presentation most suitable for its capabilities. Note that while the general meaning of each representation for the user should be retained, there usually is some information loss from one representation to the other (e.g. text/plain is missing the formatting information with respect to text/html). The alternatives should generally be ordered from the plainest to the richest, i.e. if the alternatives are again text/html and text/plain then text/plain should come first. This helps the users of non-MIME-conformant viewers in which the easiest to interpret part will show up first. Generally, a a MIME-conformant viewer should display the last representation it is capable of viewing since it is the most preferable.

This content type is often contrasted with multipart/mixed where a number of different resources are combined in a single message.

The main reason some mail services provide messages as multipart/alternative is to support different types of viewing applications on the receiving end. For example, some viewers lack the ability to render HTML and require text/plain representation for the message to be at all readable. At the same time, other viewers do have the ability to render HTML and can provide much better user experience when message is delivered as text/html. The most flexible solution to the trade-off between supporting wide range of viewers and enhancing user experience for the more capable ones is afforded by delivering both representations wrapped in a multipart/alternative message.

For details see RFC 2046.

like image 185
Adam Zalcman Avatar answered Nov 05 '22 21:11

Adam Zalcman


multipart/alternative indicates that each part is an "alternative" version of the same (or similar) content, each in a different format denoted by its "Content-Type" header. The formats are ordered by how faithful they are to the original, with the least faithful first and the most faithful last.

Mail-agents like Gmail know what they are doing, and convert the text/html to text/plain and put both alternatives into there emails and let the receiving end decide which alternative to use.

There are also mail-agents that don't know how to extract a text-only version from the html content, just because the developer did not bother to implement it, so they only send text/html with out any alternatives.

And sometimes - i call them the crazy ones - send multipart/alternative, but actually only put text/html without any alternatives. Which is not really nice, but it is not against any spec.

like image 43
esskar Avatar answered Nov 05 '22 22:11

esskar