Day 1 · How email works
Anatomy of an email: headers, MIME, encodings and attachments
Course contents
Open any message in Gmail and choose Show original, or in Outlook open Properties and look at Internet headers, and you see what an email really is: a block of plain text. This lesson takes that text apart, from the headers at the top to the MIME tree that holds the HTML, the images and the attachments. Being able to read it is the most useful single skill in email troubleshooting.
The shape of a message
RFC 5322 defines a message as header fields, then one empty line, then the body. Here is a message exactly as it was stored in a mailbox on the lab server, after the SMTP session you will type yourself in the next lesson:
Return-Path: <sender@example.org>
X-Original-To: alice@example.com
Delivered-To: alice@example.com
Received: from client.example.org (unknown [127.0.0.1])
by mail.example.com (Postfix) with ESMTP id 730EE8A21F
for <alice@example.com>; Sun, 1 Nov 2026 12:28:35 +0000 (UTC)
From: Sender <sender@example.org>
To: Alice <alice@example.com>
Subject: Hello over raw SMTP
Date: Sun, 01 Nov 2026 09:14:02 +0000
Message-ID: <lab-1@example.org>
Hi Alice, this message was typed by hand.
The last five headers were written by the sender. The first four were added by the receiving server: Return-Path records the envelope sender (the envelope itself is gone after delivery), X-Original-To and Delivered-To record the envelope recipient, and Received records the hop. Servers always add headers at the top, so a message is a stack: the oldest information is at the bottom, the newest at the top.
Rules of the format worth knowing:
- A header is
Name: value. Names are case-insensitive. A value can continue on the next line if that line starts with a space or a tab (folding); theReceivedheader above is one header on three lines. - Lines end with CRLF on the wire, and must not be longer than 998 characters (78 is recommended). Long lines are why encodings exist.
- Headers must be ASCII. Anything else is encoded (see encoded-words below), unless every server on the path supports SMTPUTF8.
DateandFromare the only headers that are strictly required.Message-IDis “should”, but in practice a message without one looks like spam.
The headers you must know
| Header | Who writes it | What it means |
|---|---|---|
From | Sender | The author, shown to the reader. The address DMARC protects |
Sender | Sender | Who actually sent it, when different from the author (a secretary, a list) |
Reply-To | Sender | Where replies should go. A favorite of phishers: the From looks right, the replies go elsewhere |
To, Cc | Sender | Visible recipients. Bcc is normally removed before sending |
Subject | Sender | The subject line |
Date | Sender | When the sender claims it was written. In the example, the sender wrote 09:14 but the server received it at 12:28: never trust Date in an investigation, trust Received |
Message-ID | Sender’s MUA or MSA | A globally unique ID, <unique@domain>. Used for threading, deduplication and searching logs |
In-Reply-To, References | Sender’s MUA | The Message-IDs this message replies to. How clients build conversation threads |
MIME-Version, Content-Type, Content-Transfer-Encoding | Sender | The MIME structure (below) |
Received | Every server on the path | One per hop: from whom, by whom, with which protocol, when |
Return-Path | The final server | The envelope sender (MAIL FROM) |
DKIM-Signature | Signing server | A DKIM signature (lesson 9) |
Authentication-Results | Receiving server | The receiver’s verdict on SPF, DKIM and DMARC |
ARC-* | Intermediaries | The ARC chain of custody (lesson 11) |
List-Unsubscribe, List-Unsubscribe-Post | Bulk senders | The unsubscribe link and one-click unsubscribe (lesson 13) |
List-Id | Mailing list software | Which list a message came from |
Auto-Submitted, Precedence | Automatic senders | Marks auto-replies and machine-generated mail, so other robots don’t reply to them |
X-... | Anyone | Non-standard headers: spam scores (X-Spam-Status), Microsoft’s X-MS-Exchange-*, campaign IDs and so on |
Reading a Received chain
Every server that handles the message adds a Received header at the top. To follow the path, read them from the bottom up. A message from a Microsoft 365 user to a Gmail user has a chain like this one (an illustrative example, shortened):
Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2101.outbound.protection.outlook.com. [40.107.22.101])
by mx.google.com with ESMTPS id ...
for <bob@gmail.com>
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Tue, 13 Oct 2026 07:41:09 -0700 (PDT)
Received: from AS8PR02MB9999.eurprd02.prod.outlook.com (2603:10a6:20b:...)
by AS8PR02MB9999.eurprd02.prod.outlook.com with HTTP; Tue, 13 Oct 2026 14:41:07 +0000
The bottom header shows the message entering Microsoft’s system from the user (over HTTP, because it was sent from Outlook on the web). The top one shows Google’s MX receiving it from Microsoft’s outbound server, with TLS 1.3. Things to look for in each line:
- from what the connecting server claimed in its HELO, followed by what the receiver found itself in brackets: reverse DNS and the real IP. The part in brackets is the trustworthy part.
- by which server received it, and with which protocol:
SMTP,ESMTP,ESMTPS(with TLS),ESMTPSA(with TLS and authentication),LMTP,HTTP. - The time stamp. Comparing time stamps between hops shows where a message was delayed. Mind the time zones.
MIME: one message, many parts
The original format could carry only one ASCII text. MIME (Multipurpose Internet Mail Extensions, RFC 2045 to 2049) keeps the same format but adds three headers that let a body contain anything:
MIME-Version: 1.0, always this value.Content-Type: what the body is:text/plain; charset=utf-8,text/html,image/png,application/pdf, or a multipart type that contains other parts.Content-Transfer-Encoding: how the body was turned into safe text:7bit,8bit,quoted-printable,base64orbinary.
A multipart body is a list of parts separated by a boundary, a random string declared in the Content-Type header. Each part has its own headers, an empty line and its own body, and a part can itself be multipart. The result is a tree. Three multipart types cover almost every email:
| Type | Meaning | Used for |
|---|---|---|
multipart/alternative | The same content in several formats, simplest first, best last. The client shows the last one it can display | A plain-text and an HTML version of the same message |
multipart/related | One main part plus the resources it refers to | HTML plus the images it embeds with cid: |
multipart/mixed | Independent parts in order | The message plus its attachments |
Two other headers matter for the parts:
Content-Disposition: attachment; filename="invoice.pdf"tells the client to show the part as an attachment;inlineasks it to show it in the message.Content-ID: <logo>gives a part an ID, so the HTML can refer to it as<img src="cid:logo">. This is one of the ways to put images in an email; lesson 15 compares all of them.
Transfer encodings
SMTP was built for 7-bit ASCII text in lines of limited length. Anything else is encoded:
- Quoted-printable keeps ASCII as it is and writes every other byte as
=plus two hex digits:Caféin UTF-8 becomesCaf=C3=A9. A line that would be too long is broken with a “soft” line break, a=at the end of the line. It’s good for text that is mostly ASCII, because a human can still read it. - Base64 turns every 3 bytes into 4 characters from
A–Z a–z 0–9 + /. It’s used for binary files and for text in non-Latin scripts. It makes everything about 33% bigger (a little more with the line breaks), which is why a 15 MB attachment can exceed a 20 MB size limit. - 8bit and binary send the bytes unchanged. They need the
8BITMIME(orBINARYMIME) SMTP extension on every hop, which most modern servers support, but encoded content always works.
Encoded-words: non-ASCII in headers
A header can’t contain raw UTF-8 (without SMTPUTF8), so a subject in Persian, German or with an emoji is written as an encoded-word (RFC 2047): =?charset?encoding?text?=, where the encoding is B (base64) or Q (a variant of quoted-printable).
Subject: Q3 report =?utf-8?b?4oCUINqv2LLYp9ix2LQg4piA?=
Decoded, that’s Q3 report — گزارش ☀. Display names use the same trick: From: =?utf-8?q?Jos=C3=A9?= <jose@example.com>. Attachment file names with non-ASCII characters use a related encoding, filename*=utf-8''... (RFC 2231).
Attachments and size limits
- Size limits apply to the encoded message, so an attachment grows by about a third. Gmail accepts messages up to 25 MB when sending, Microsoft 365’s default limits are in the same range, and many company servers are lower. Big files belong in a shared link (OneDrive, Google Drive, any file-sharing service), not in email.
- Servers announce their limit with the SMTP
SIZEextension, and refuse bigger messages with552 5.3.4. - Security filters block dangerous attachment types by extension and by content:
.exe,.js,.vbs,.iso,.lnk, macro-enabled Office files and the like. Gmail also blocks archives that contain them, and password-protected archives that it can’t scan are often quarantined. winmail.dat: Outlook sometimes sends rich-text messages in Microsoft’s TNEF format, which other clients see as a uselesswinmail.datattachment. The fix is to send in HTML or plain text, on the sender’s side.
EML, MSG and MBOX
When you save or export mail you meet these formats:
- .eml: one message in the raw RFC 5322 format you saw in this lesson. Any client can open it, and it’s the best format to send to a colleague or a support team when you need the full headers.
- .msg: Outlook’s own format for one message (a binary compound file). Convert it, or open it in Outlook.
- mbox: many messages in one file, each starting with a
Fromline. Classic Unix mail and Google Takeout exports use it. - Maildir: one file per message in a directory (
new/,cur/,tmp/). Dovecot and Postfix use it in the lab. - .pst / .ost: Outlook’s data files. PST is an archive or export; OST is the local cache of an Exchange or Microsoft 365 mailbox, not a backup.