The Message Itself
Headers, body, and the envelope that is not either.
Everything after DATA is the message. None of it is the envelope.
Headers, blank line, body
The same shape as HTTP — Name: value lines, one empty line, then content:
EHLO test.local
MAIL FROM:<[email protected]>
RCPT TO:<[email protected]>
DATA
From: [email protected]
To: [email protected]
Subject: Shape
This is the body.
.
QUITThe four a client shows you
From, To, Subject, Date — and a client makes its own decisions about the rest.
None of the four is required. Chapter 2’s examples had only Subject: and were queued
without complaint.
Two senders
MAIL FROM: is the envelope sender; From: is a header. They are unrelated:
EHLO test.local
MAIL FROM:<[email protected]>
RCPT TO:<[email protected]>
DATA
From: [email protected]
Subject: TwoSenders
body
.
QUITcurl -s localhost:8025/api/v2/messages | python3 -c '
import json, sys
d = json.load(sys.stdin)
m = [x for x in d["items"]
if "TwoSenders" in str(x["Content"]["Headers"].get("Subject", ""))][0]
h = m["Content"]["Headers"]
print("From: ", h["From"][0])
print("Return-Path: ", h["Return-Path"][0])'Return-Path was stamped from the envelope. Bounces go to bounces@; the reader sees
noreply@.
Two recipient lists
RCPT TO: routes the message; To: is decoration. Send to two, name one:
EHLO test.local
MAIL FROM:<[email protected]>
RCPT TO:<[email protected]>
RCPT TO:<[email protected]>
DATA
From: [email protected]
To: [email protected]
Subject: BccTest
body
.
QUITcurl -s localhost:8025/api/v2/messages | python3 -c '
import json, sys
d = json.load(sys.stdin)
m = [x for x in d["items"]
if "BccTest" in str(x["Content"]["Headers"].get("Subject", ""))][0]
print("envelope rcpt:", [r["Mailbox"] + "@" + r["Domain"] for r in m["To"]])
print("header To: ", m["Content"]["Headers"]["To"])'That is Bcc — a RCPT TO: with no matching header line, and no Bcc header anywhere.
A Bcc recipient cannot see the others because the information was never in the message —
your client strips the header before sending.
Spoofing, demonstrated
Nothing checks that the two senders agree:
EHLO test.local
MAIL FROM:<[email protected]>
RCPT TO:<[email protected]>
DATA
From: "Your Bank" <[email protected]>
To: [email protected]
Subject: Spoofed
Please confirm your details.
.
QUITcurl -s localhost:8025/api/v2/messages | python3 -c '
import json, sys
d = json.load(sys.stdin)
m = [x for x in d["items"]
if "Spoofed" in str(x["Content"]["Headers"].get("Subject", ""))][0]
print("envelope from:", m["From"]["Mailbox"] + "@" + m["From"]["Domain"])
print("header From: ", m["Content"]["Headers"]["From"][0])'Message-ID and threading
A client supplies its own, and the server keeps it:
EHLO test.local
MAIL FROM:<[email protected]>
RCPT TO:<[email protected]>
DATA
From: [email protected]
Subject: Re: Thread
Message-ID: <[email protected]>
In-Reply-To: <[email protected]>
References: <[email protected]> <[email protected]>
reply
.
QUITcurl -s localhost:8025/api/v2/messages | python3 -c '
import json, sys
d = json.load(sys.stdin)
m = [x for x in d["items"]
if "Thread" in str(x["Content"]["Headers"].get("Subject", ""))][0]
h = m["Content"]["Headers"]
for k in ("Message-ID", "In-Reply-To", "References"):
print(k + ":", h[k][0])'In-Reply-To names the parent, References the chain back to the root. Clients rebuild
the tree from those two.
Received headers
Each hop adds one at the top, so the list reads newest-first:
curl -s localhost:8025/api/v2/messages | python3 -c '
import json, sys
d = json.load(sys.stdin)
m = [x for x in d["items"]
if "Thread" in str(x["Content"]["Headers"].get("Subject", ""))][0]
print(m["Content"]["Headers"]["Received"][0].split("\n")[0].strip())'One hop, because MailHog is the only server. A real delivery stacks four or five, read bottom to top.
Each one carries a timestamp, so the gap between two is where the message waited. That is how you find a slow hop.
Return-Path and Reply-To
Three addresses can appear on one message, answering three questions:
| Header | Answers | Set by |
|---|---|---|
Return-Path |
where do bounces go | the receiving server, from the envelope |
From |
who wrote this | the sender |
Reply-To |
where should a reply go | the sender |
Headers the server adds
You wrote two headers. Four came out:
curl -s localhost:8025/api/v2/messages | python3 -c '
import json, sys
d = json.load(sys.stdin)
m = [x for x in d["items"]
if "TwoSenders" in str(x["Content"]["Headers"].get("Subject", ""))][0]
print("\n".join(sorted(m["Content"]["Headers"])))'Three were added in transit. The first two you can never set; the third you can, and the server left yours alone above.