MIME message structure

Friday 25 April 2003

You’d think after 18 months of working on the Kubi Client, I would be able to do MIME structures in my sleep. But I had to look it up again today, so I’m putting this here so I can find it again. Also, I figure if I need to look something up, someone else out there may find it useful.

There are three commonly-used Content-Type headers for structuring MIME messages:

  • multipart/mixed for adding attachments to a message,
  • multipart/related for combining inline images with a message, and
  • mulitpart/alternative for collecting different representations of a message.

For example (indentation is just for cosmetic presentation):

Content-Type: multipart/mixed; boundary="mixed-boundary"

This is a multipart message in MIME format.
   Content-Type: multipart/related; boundary="related-boundary"
      Content-Type: multipart/alternative; boundary="alternative-boundary"
         Content-Type: text/html

         <html><body><p>This is the HTML message.</p></body></html>

         Content-Type: text/plain

         This is the plain text message.
      Content-Type: image/jpeg

      (.. jpeg data ..)
   Content-Type: application/octet-stream; name="file.dat"
   Content-Disposition: attachment; name="file.dat"

   (.. file.dat data ..)

There. As Maude said, “Now I’ll always know where it is.”



Thanks for your mini-article on MIME structure. I'm currently learning more than I want to about this topic, but, also currently, know less than I need. And, 'Harold and Maude' was one of my favourite films ever.

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
Comment text is Markdown.