An email has three parts: headers, a body and optional attachments. Headers are lines of metadata such as From, To, Subject, Date and the delivery trail. The body is the message content, as plain text, HTML or both. Attachments are files encoded inside the message. Knowing how email headers and body are separated helps you read, debug and build messages correctly.
Everything in an email is text on the wire. Files and non-English characters are converted to text with a standard called MIME, which is how one message can carry a formatted body and several attachments.
An email message follows the format defined in RFC 5322. It has a header section, then one empty line, then the body. The empty line is the only separator, so it matters.
Each header is a name, a colon and a value. A long value can continue on the next line if that line starts with a space or tab. The first blank line ends the headers, and everything after it is the body.
| Header | Meaning |
|---|---|
From | The author shown to the reader |
To | Main recipients |
Cc | Copied recipients, visible to everyone |
Bcc | Hidden recipients, not shown in delivered copies |
Subject | One line summary |
Date | When the sender's client created the message |
Message-ID | A unique identifier for this message |
Reply-To | Where replies go if different from From |
In-Reply-To and References | Link a reply to the earlier messages in a thread |
Received | One line added by each server that handled the message |
Content-Type | Format of the body, such as plain text or multipart |
Some headers are written by you or your mail client, such as Subject. Others, mostly Received, are added by servers on the way and are the most reliable source when you trace a message.
There are two sets of addresses. The envelope is what the servers use during the SMTP conversation (MAIL FROM and RCPT TO). The headers are what the reader sees. They usually match, but they do not have to.
This is how Bcc works. The server gets a RCPT TO command for the hidden recipient, but the Bcc address is not written into the headers of the copies. It is also why a mailing list message can show the author in From while bounces go to a different envelope address.
The body can be plain text, HTML, or a mix. Mail clients normally send both versions so that a client that cannot show HTML still shows readable text. The Content-Type header tells the reader how the body is built.
The multipart/alternative type means the parts are different versions of the same content, and the client shows the best one it supports. The boundary text marks where each part begins and ends. The final boundary ends with two extra dashes.
HTML email is not the same as a web page. Many clients remove scripts and ignore modern CSS, so keep layouts simple and always include a plain text alternative.
SMTP was designed for 7-bit text, so binary files such as images and PDFs are converted to text before sending. MIME, the Multipurpose Internet Mail Extensions, describes how. Most attachments are encoded with Base64, which turns binary data into letters, digits and a few symbols.
Here multipart/mixed means the parts are different things: the text and a file. Content-Disposition: attachment tells the client to offer the file for download rather than to show it inside the message. Base64 makes the data about one third larger, which is why mail servers usually limit messages to roughly 20 to 50 MB depending on the provider, and why large files are better shared as a link.
Python's standard library can build and inspect these parts for you. This example works on Python 3.13 and 3.14 with no extra packages.
The library chose multipart/mixed automatically when an attachment was added, and walk() visits the container and each part inside it.
Header lines must be ASCII, so a subject with accents or other scripts is wrapped in an encoded word such as =?UTF-8?B?...?=. Your mail client decodes it for display. If you write your own code, use a library rather than building these strings by hand.
In the Subject header, which is part of the header section and not the body.
Yes. Every client has a menu item such as Show original or View source. It shows the full headers.
Base64 encoding expands binary data by about 33 percent, plus a little extra for line breaks.
Not in the copies that recipients get. The sender's own saved copy may show it.
An email is a header section, a blank line and a body. Headers carry metadata and a trace of servers, the body carries plain text and HTML, and MIME multipart structures wrap alternatives and attachments. Attachments are Base64 encoded, so they grow in size. The envelope used by servers is separate from the headers shown to the reader.