MIME Types: How Email and the Web Identify Content - Yenra

Understand Content-Type, multipart email, attachments, and the difference between a filename and a media type.

An ivory envelope holds distinct navy, teal, and amber content cards within a glass frame.
Conceptual illustration: a multipart message packages separately described pieces of content.

MIME (Multipurpose Internet Mail Extensions) provides conventions for describing and packaging message content. Its media types also identify formats on the web: an HTTP response can declare HTML, an image, a PDF, or another kind of data through Content-Type.

Read a media type

A media type normally has a type and subtype separated by a slash. Optional parameters add information. In text/html; charset=utf-8, text is the type, html is the subtype, and charset identifies the character encoding.

Common media types
ValueTypical contentUseful distinction
text/plainPlain textCharacters are presented as text rather than HTML elements.
text/htmlHTML documentThe browser interprets markup as a document.
image/jpegJPEG imageA .jpg or .jpeg filename commonly accompanies this type.
application/pdfPDF documentViewing behavior also depends on client settings and disposition.
application/jsonJSON dataThe body should follow JSON syntax.
multipart/mixedA body containing separately described partsA boundary separates the parts.

The IANA media-type registry records registered names. A filename extension is a naming convention; Content-Type is a message declaration; the actual bytes have their own format. Check all three when a file behaves unexpectedly.

Follow a multipart message

This simplified MIME body contains a text note and a text attachment. Delivery headers such as From and To are omitted because this is an anatomy example, not an email to send.

MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="practice-boundary"

--practice-boundary
Content-Type: text/plain; charset=utf-8

Here is the fictional note.
--practice-boundary
Content-Type: text/plain; charset=utf-8
Content-Disposition: attachment; filename="note.txt"

Remember to return the atlas.
--practice-boundary--

The outer Content-Type announces the multipart container and names its boundary. Each delimiter begins with two hyphens followed by that boundary. The final delimiter adds two more hyphens to close the container. Each part has its own headers, a blank line, and content.

RFC 2046 defines multipart organization. Mixed groups separate parts together; alternative supplies different representations of the same information, such as plain text and HTML. A mail client chooses a representation it supports. Nesting these structures lets a message offer alternatives while also carrying attachments.

The filename suggests how an attachment should be named when saved. The Content-Disposition specification distinguishes attachment and inline presentation and treats supplied filenames as information the receiving software must handle carefully.

Separate format, encoding, and encryption

MIME transfer encodings such as base64 represent data in a form suitable for message transport. They do not change a JPEG into a different image format. The receiver decodes the representation before using the original bytes. The MIME format specification defines Content-Type and Content-Transfer-Encoding.

Base64 is reversible encoding, not secrecy: anyone with the encoded content can decode it. In HTTP, Content-Encoding commonly describes compression; it serves a different role from email's Content-Transfer-Encoding. Keep these fields distinct when debugging.

S/MIME adds cryptographic message formats for functions such as digital signatures and encryption. Their protection depends on certificates, keys, and the supported workflow. Ordinary MIME formatting alone does not provide these protections. See the S/MIME message specification.

Diagnose the mismatch

  1. Inspect the specific response or attachment, including its actual body.
  2. Compare its declared type with its content and intended use.
  3. For a website you operate, correct the route or server's type mapping as appropriate, then request the resource again.
  4. For an unexpected attachment, confirm the sender and purpose before opening it. A reassuring extension or media type is not evidence of safe content.

Browser decisions can also depend on context, content inspection, and the X-Content-Type-Options: nosniff response header. The MIME Sniffing Standard describes browser classification behavior. Use accurate media types and inspect the browser's actual error rather than assuming every download or display issue has the same cause.

Keep learning