Email MIME Structure Explained: multipart/mixed, multipart/alternative, and How Email Is Really Built
Modern emails are far more than plain text messages. They include HTML, inline images, attachments, multiple languages, and rich formatting β all transported through protocols originally designed for simple ASCII text.
The system that makes this possible is MIME (Multipurpose Internet Mail Extensions).
This article explains how MIME works, what multipart/mixed and multipart/alternative mean, and how real emails are structured under the hood.
What Is MIME?
MIME is a standard that extends email to support:
- Attachments
- HTML content
- Inline images
- Multiple encodings
- Non-ASCII characters
MIME works entirely through email headers and body structure, without changing SMTP itself.
Content-Type and Content-Transfer-Encoding
Every MIME part includes at least two critical headers:
Content-Typeβ what the data isContent-Transfer-Encodingβ how itβs encoded
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
These headers tell email clients exactly how to interpret each section.
multipart/* β Emails with Multiple Parts
When an email contains more than one piece of content, it uses a multipart MIME type.
Content-Type: multipart/mixed; boundary="abc123"
The boundary defines where each part starts and ends.
multipart/mixed: Attachments and Content
multipart/mixed is the most common multipart type. It is used when an email contains attachments.
Typical structure:
- Main message body
- One or more attachments
--abc123
Content-Type: text/plain
Hello
--abc123
Content-Type: application/pdf
Content-Disposition: attachment; filename="file.pdf"
--abc123--
Email clients display the first part as the message and treat the remaining parts as attachments.
multipart/alternative: Text and HTML Versions
multipart/alternative is used when the same content is provided in multiple formats.
- Plain text version
- HTML version
Content-Type: multipart/alternative
Email clients choose the best version they support β typically HTML.
Nested Multipart Structures
Real-world emails often combine multiple MIME types:
multipart/mixed(outer)multipart/alternative(inner)- Attachments encoded with Base64
This nesting allows:
- HTML + text content
- Inline images
- Multiple attachments
MIME and Encodings
MIME defines how content is structured β encoding defines how bytes are represented.
| Encoding | Used For |
|---|---|
| Quoted-Printable | Text and HTML |
| Base64 | Attachments |
| 7bit / 8bit | Simple ASCII |
MIME in EML and MBOX Files
EML and MBOX formats store MIME messages exactly as transmitted.
Understanding MIME is essential for:
- Email parsing tools
- Security analysis
- Forensic investigations
- Email migration and archiving
Common MIME Problems
- Incorrect boundary definitions
- Wrong content type
- Broken encoding declarations
- Inline images treated as attachments
- HTML displayed as plain text
Final Thoughts
MIME is the hidden framework behind every modern email. Without it, attachments, HTML, and international content would not exist.
Understanding MIME structure transforms email from a fragile black box into a predictable, debuggable system.