E-mail investigations
Practical, exam-focused notes on how to investigate e-mail: how e-mail is delivered and logged, how to read headers for provenance, how SPF/DKIM/DMARC work, preserving e-mail as evidence, and common exam tasks.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
E-mail is a common vector for cyber crime (phishing, fraud, malware delivery) and a common source of digital evidence. An engineer uses e-mail investigation skills to establish message provenance, identify spoofing, collect admissible evidence, and support incident response and forensics.
Key ideas
All new terms are defined the first time they appear.
E-mail message (message): the complete object sent by a user, including headers and body (MIME parts). When we say "raw message" we mean the message exactly as received by a mail server, including all header lines and body bytes.
Mail User Agent (MUA): the client program used by a person to send/receive mail (e.g., Outlook, Thunderbird, webmail UI). MUAs submit messages to a Mail Submission Agent.
Mail Submission Agent (MSA): the server that receives mail from an MUA (usually on port 587) and forwards it to the Mail Transfer Agent.
Mail Transfer Agent (MTA): the server (like postfix, sendmail, Exchange) that routes mail between domains using SMTP (Simple Mail Transfer Protocol). MTA behaviour creates the header chain we analyse.
Mail Delivery Agent (MDA): the server that delivers mail to the recipient mailbox (e.g., dovecot). It stores or hands mail to the MUA for retrieval.
SMTP: the protocol used by MTAs to send mail between servers. By default MTAs listen on port 25 for server-to-server transfer; MSAs commonly use port 587 for submission (ESMTP with STARTTLS and AUTH); port 465 is registered for implicit TLS submission (“submissions”) per RFC 8314 (formerly called SMTPS). (Verify exact ports and conventions for your exam syllabus.) In Received headers, “with ESMTP” means extended SMTP; “with ESMTPS” indicates SMTP over TLS.
Header: a line in the message beginning with a field name and a colon, e.g.,
From:orReceived:. The ordering of Received headers is important: each MTA that handles the message prepends aReceivedheader. Therefore the bottom-most Received header is closest to the message origin (the first MTA that accepted the message from the sender).Received header chain: a sequence of
Receivedheaders added by each MTA hop. To find the apparent origin, read Received headers from bottom to top, checking IP addresses and hostnames. Assumptions: MTAs are honest about adding headers, but headers can be forged by the sender for fields inside the message; MTAs under the sender's control can add false Received headers before submission.Return-Path (also called the bounce address): the envelope sender used in SMTP (MAIL FROM). This is not the same as the
From:header (the display author). Envelope fields are part of SMTP transaction and often recorded in server logs. The Return-Path header itself is typically added by the final delivery MTA; it may be absent or different before final delivery, so prefer server logs for authoritative envelope data.Message-ID: a unique identifier added by the originating MUA or MTA; it helps link messages but can be forged.
SPF (Sender Policy Framework): a DNS TXT record that lists which IP addresses or hosts are authorised to send mail for a domain. An SPF record example:
v=spf1 ip4:203.0.113.0/24 include:_spf.example.net -all. During SPF check the receiver compares the SMTP sending IP with the domain's SPF rules to produce Pass/Fail/Neutral; if the MAIL FROM is empty (e.g., bounce messages), SPF evaluation falls back to the HELO/EHLO domain.DKIM (DomainKeys Identified Mail): a cryptographic signature added to the message headers and body by an authorised MTA. The receiver fetches the public key from DNS (a TXT record at a selector like
selector._domainkey.example.com) and verifies the signature. If valid, DKIM ties the signed headers/body to the domain that added the signature.DMARC (Domain-based Message Authentication, Reporting and Conformance): a policy tied to a domain that tells receivers how to handle messages that fail SPF/DKIM checks and where to send reports (DNS record in
_dmarc.example.com). DMARC links the visibleFrom:domain with SPF/DKIM results (alignment).Authentication-Results: a header added by receiving MTAs that records the receiver’s evaluation of SPF, DKIM, and DMARC (e.g., pass/fail and reasons). Use it to see what the receiving system actually verified.
Provenance: the claimed origin of a message (who sent it and from where). Provenance is established by combining Received header analysis, SMTP logs, SPF/DKIM/DMARC results, and server logs.
Header forging and spoofing: since some headers (like
From:) are part of the message body and not authenticated by SMTP itself, attackers can present a falseFrom:. Therefore always rely on envelope and server-recorded data, not only headers in the message.Evidence preservation: to keep email admissible, capture the full raw message (RFC 5322), note capture time with timezone, compute hashes (e.g., SHA-256) of the raw file, collect server logs, and keep a written chain-of-custody. Use write-blocked media or exported files with clear provenance.
Time and timezones: Received headers contain timestamps with timezones. Convert all times to UTC for comparison. Be careful with daylight saving and misconfigured MTAs reporting wrong local time.
Diagram to draw (for exam): a flow diagram with boxes left-to-right: MUA -> MSA (port 587) -> MTA1 -> MTA2 -> MDA -> Recipient MUA. Above each arrow label the protocol (SMTP) and the TCP port. Under each MTA box list the logged items:
Receivedheader added, timestamp, connecting IP, HELO/EHLO string. Draw the Received header stack vertically: bottom box is the earliest Received (from sender), top is the last MTA before delivery. Label clearly.
Formulas
H = SHA256(message) — H is the 256-bit SHA-256 hash of the raw message bytes. Units: bits (digest length 256 bits). Applies to digital evidence integrity checks.
v=spf1 <mechanisms> <modifiers> — notation for SPF DNS TXT record. <mechanisms> may include ip4:, ip6:, include:, a, mx; modifier examples: ~all (softfail), -all (fail). Applies when performing SPF checks.
DKIM-Signature: v=1; a=algorithm; d=domain; s=selector; h=header-list; bh=body-hash; b=signature — key fields in a DKIM-Signature header. d is signing domain, s is selector, h lists signed header fields, and bh is the body hash. Applies during DKIM verification.
_dmarc.<domain> TXT: v=DMARC1; p=policy; rua=mailto:report@example.com — DMARC DNS record fields; p is policy (none, quarantine, reject).
Worked examples
Example 1 — Find apparent origin from Received headers (numeric/timestamp example) Given raw Received headers (bottom three shown, earliest at bottom): Received: from mail-192-0-2-45.example.net (mail-192-0-2-45.example.net [192.0.2.45]) by mx2.victim.org with ESMTPS id G7A1; Mon, 08 Jun 2026 06:30:10 +0530 Received: from [10.0.0.5] (unknown [198.51.100.22]) by mail-192-0-2-45.example.net with SMTP id H3B2; Mon, 08 Jun 2026 01:00:05 +0000 Received: from sender-laptop.local (sender.example.com [10.0.0.5]) by smtp.office.example with ESMTP id K9C4; Mon, 08 Jun 2026 00:59:50 +0000 Steps:
- Read Received headers from bottom to top. The bottom-most shows
sender-laptop.localconnecting tosmtp.office.examplewith IP[10.0.0.5](private IP). This is likely a private LAN address and not routable on the internet. - The next (middle) Received shows connection to
mail-192-0-2-45.example.netfromunknown [198.51.100.22]and records timestamp01:00:05 +0000. - The top shows delivery to
mx2.victim.orgfrommail-192-0-2-45.example.net [192.0.2.45]at06:30:10 +0530. - Determine candidate external origin:
198.51.100.22(middle) and192.0.2.45(top) are public. The earliest public IP in bottom-to-top order is198.51.100.22which likely passed the message tomail-192-0-2-45. Therefore the apparent origin IP is 198.51.100.22. - Convert times to UTC to compare:
01:00:05 +0000is already UTC.06:30:10 +0530equals01:00:10 +0000. Times align (delivery happened 5 seconds after the hop). Conclusion: apparent sending IP = 198.51.100.22. Note: check server logs for 198.51.100.22 and remember private IPs (10.x) are internal and need correlation to NAT logs.
Example 2 — SPF check (numeric/IP example)
Given: Domain example.com has SPF record v=spf1 ip4:203.0.113.0/24 -all. Mail received claims MAIL FROM user@example.com and connecting IP is 203.0.113.45.
Steps:
- Receiver extracts envelope MAIL FROM domain =
example.com. - DNS lookup for example.com TXT returns the SPF record.
- Check sending IP 203.0.113.45 against
ip4:203.0.113.0/24: it is inside that range. - Result: SPF evaluation = Pass. Because the SPF record ends with
-all, any IP not matched would be Fail. - Conclusion: SPF does not prove the author but shows the sending IP was authorised by example.com's administrators.
Example 3 — Model answer: preserving e-mail evidence (short theory answer) Full-mark points to include:
- Capture the raw RFC 5322 message (headers + body) in a file; also collect server SMTP logs and mailbox metadata.
- Compute and record cryptographic hash (SHA-256) of the raw message file and of any exported evidence files; note hashing algorithm and exact command/tool used.
- Note capture date/time with timezone and convert to UTC; document who captured and using what machine/tool.
- Preserve original media or export to write-protected storage; create a chain-of-custody document recording each transfer, date/time, purpose, and signatures.
- If live system: follow incident response guidelines (see Incident response methodology topic) to minimise alteration; record volatile data if needed (open TCP connections, running processes) and justify method in report.
- Maintain separation of duties and avoid altering server logs; always work on copies.
Common mistakes
- Trusting headers that may be added by webmail front-ends like
X-Originating-IPwithout corroborating server logs. - Not converting timestamps to UTC or ignoring timezone offsets, leading to misordered events.
- Relying solely on SPF or DKIM: SPF checks the sending IP, DKIM verifies a signature, DMARC provides policy — use them together for higher confidence.
- Using weak hashes (MD5, SHA-1) for evidence without noting deprecation; prefer SHA-256 for integrity.
For your exam
Question types you can expect:
- Definitions and short notes (define Received header, SPF, DKIM, DMARC, MTA, chain of custody).
- Diagram: draw and label mail flow and Received header stack — include ports and which server adds which header.
- Long question: step-by-step procedure to investigate a phishing e-mail and preserve evidence — include tools and hashing steps.
- Numerical/trace problem: given Received headers and timestamps, find apparent origin IP and convert times to UTC.
- Short derivation/logic: explain why bottom-most Received is earliest and how an attacker can forge headers.
What a full-marks answer includes:
- Precise definitions of terms with bold identifiers, correct Received header ordering (bottom-up), correct conversion of timezones to UTC, demonstration of SPF/DKIM/DMARC verification logic, and explicit evidence preservation steps (raw export, hash, chain-of-custody). For diagrams, labels for ports, protocols and which server adds headers.
Quick check
- Which header field is added by each MTA hop and in which order should you read them to find the origin?
- What does an SPF record
-allqualifier mean for a sending IP not listed in the policy? - Name two pieces of data you must record when exporting an e-mail to be used as evidence.
Answers: 1)
Receivedheader; read bottom-to-top (bottom is earliest). 2)-allmeans SPF Fail for IPs not listed (unauthorized sending IP). 3) raw message file (full headers + body) and its cryptographic hash (e.g., SHA-256) plus capture timestamp and capture method.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?