Wrap-up

Email cheat sheet and final exam: ports, DNS records, codes, RFCs

lesson 19 / 1924 minpublished
Course contents
On this page
  1. Ports
  2. DNS records, ready to adapt
  3. SMTP reply codes
  4. Headers to read when troubleshooting
  5. Commands
  6. RFCs worth knowing
  7. Final exam: questions
  8. Final exam: answers
  9. The complete checklist: what I can do without documentation
  10. Roadmap: what to learn next

This is the page to come back to after the course. It collects the ports, DNS records, codes, commands and RFCs you’ll look up again, then tests everything with a 50-question final exam, followed by a checklist of what you should be able to do without documentation and a roadmap for what to study next.

Ports

PortProtocolUse
25SMTPServer to server (MX). STARTTLS. Never for users
587SMTP submissionClients and apps: STARTTLS, then AUTH
465SMTP submission over implicit TLSClients and apps: TLS from the first byte (preferred by RFC 8314)
2525(unofficial)Alternative submission port at some ESPs
143 / 993IMAP / IMAP over TLSReading mail; use 993
110 / 995POP3 / POP3 over TLSDownloading mail; use 995
4190ManageSieveManaging server-side filters
443HTTPSWebmail, Exchange/Graph, Gmail API, JMAP, autodiscover, MTA-STS policy
24 or a Unix socketLMTPMTA to mailbox server, local only

DNS records, ready to adapt

A domain on Google Workspace (replace the DKIM key and the report address):

example.com.                      MX    1 smtp.google.com.
example.com.                      TXT   "v=spf1 include:_spf.google.com ~all"
google._domainkey.example.com.    TXT   "v=DKIM1; k=rsa; p=MIIBIjANBgkqh...IDAQAB"
_dmarc.example.com.               TXT   "v=DMARC1; p=reject; rua=mailto:dmarc@example.com"
_mta-sts.example.com.             TXT   "v=STSv1; id=2026110101"
_smtp._tls.example.com.           TXT   "v=TLSRPTv1; rua=mailto:tlsrpt@example.com"

A domain on Microsoft 365 (copy the exact MX and DKIM targets from your admin portals):

example.com.                      MX    0 example-com.mail.protection.outlook.com.
example.com.                      TXT   "v=spf1 include:spf.protection.outlook.com -all"
autodiscover.example.com.         CNAME autodiscover.outlook.com.
selector1._domainkey.example.com. CNAME (target shown in the Defender portal)
selector2._domainkey.example.com. CNAME (target shown in the Defender portal)
_dmarc.example.com.               TXT   "v=DMARC1; p=reject; rua=mailto:dmarc@example.com"

A domain that never sends or receives mail:

example.net.                      MX    0 .
example.net.                      TXT   "v=spf1 -all"
_dmarc.example.net.               TXT   "v=DMARC1; p=reject; sp=reject; adkim=s; aspf=s"
*._domainkey.example.net.         TXT   "v=DKIM1; p="

The MTA-STS policy file at https://mta-sts.example.com/.well-known/mta-sts.txt:

version: STSv1
mode: testing
mx: smtp.google.com
max_age: 86400

Switch mode to enforce, raise max_age to a week or more, and change the id in the TXT record whenever you edit it.

SMTP reply codes

First digitMeaningSender’s action
2SuccessContinue
3Send more (354 after DATA, 334 during AUTH)Send
4Temporary failureQueue and retry
5Permanent failureStop and bounce

Enhanced codes class.subject.detail, subjects: 1 address, 2 mailbox, 3 mail system, 4 network/routing, 5 protocol, 6 content, 7 security/policy. The ones you’ll see most: 5.1.1 no such user, 5.2.2 mailbox full, 5.3.4 too big, 5.7.1 refused by policy, 5.7.26 (Gmail) unauthenticated/DMARC, 5.7.25 (Gmail) no PTR, 4.7.28 (Gmail) rate limited, 5.7.515 (Outlook.com) authentication requirements, 5.7.606 (Microsoft) banned IP.

Headers to read when troubleshooting

HeaderTells you
Authentication-ResultsSPF, DKIM and DMARC results and the domains checked (smtp.mailfrom, header.d/header.i, header.from)
Received (bottom up)The path, the IPs, TLS or not, and the time at each hop
Return-PathThe envelope sender (where bounces go)
DKIM-SignatureWho signed (d=), which key (s=), which headers (h=)
ARC-*What earlier hops saw (forwarding, mailing lists)
X-Spam-Status, X-Spamd-ResultSpamAssassin or Rspamd rules and score
X-Forefront-Antispam-Report, X-Microsoft-AntispamMicrosoft’s SCL, SFV, CIP and BCL
List-Unsubscribe, List-Unsubscribe-PostOne-click unsubscribe
Message-IDThe ID to search in every log and message trace

Commands

dig +short example.com MX                      # where mail for the domain goes
dig +short example.com TXT | grep spf          # SPF
dig +short selector._domainkey.example.com TXT # a DKIM key
dig +short _dmarc.example.com TXT              # DMARC
dig +short -x 203.0.113.25                     # PTR of a sending IP
curl -s https://mta-sts.example.com/.well-known/mta-sts.txt
openssl s_client -connect mx.example.com:25 -starttls smtp -crlf      # TLS on an MX
openssl s_client -connect smtp.example.com:465 -crlf                  # implicit TLS
swaks --to you@example.net --server smtp.example.com:587 --tls --auth-user you@example.com
swaks --to postmaster@example.com --server mx.example.com --quit-after RCPT  # does the MX accept?
postqueue -p; postqueue -f; postcat -vq ID; postsuper -d ID           # Postfix queue
grep QUEUEID /var/log/mail.log                                        # one message's life
doveadm search -u alice mailbox INBOX subject "invoice"               # Dovecot
spamassassin -t < message.eml                                         # score a message

RFCs worth knowing

TopicRFC
SMTP5321 (2008), first version 821 (1982)
Message format5322 (2008), first version 822 (1982)
MIME2045 to 2049 (1996); encoded-words 2047; multipart/related 2387; cid: URLs 2392
Submission, and TLS for submission and access6409 (2011), 8314 (2018)
STARTTLS, AUTH3207 (2002), 4954 (2007)
SMTP extensionsSIZE 1870, PIPELINING 2920, CHUNKING 3030, 8BITMIME 6152, SMTPUTF8 6531, REQUIRETLS 8689
Enhanced status codes, DSN, reports3463 (2003), 3461 to 3464 (2003), multipart/report 6522 (2012)
Null MX7505 (2015)
LMTP2033 (1996)
POP3, IMAP1939 (1996); IMAP4rev1 3501 (2003), IMAP4rev2 9051 (2021); IDLE 2177; CONDSTORE/QRESYNC 7162; MOVE 6851; SPECIAL-USE 6154
JMAP8620, 8621 (2019)
Sieve, ManageSieve5228 (2008), 5804 (2010)
SRV records for mail services6186 (2011)
SPF7208 (2014)
DKIM6376 (2011); crypto update 8301 (2018); Ed25519 8463 (2018)
DMARC9989, 9990, 9991 (May 2026), which replaced 7489 (2015)
Authentication-Results8601 (2019)
ARC8617 (2019)
MTA-STS, TLS-RPT8461, 8460 (2018)
DANE for SMTP, TLSA7672 (2015), 6698 (2012)
List headers, one-click unsubscribe2369 (1998), 8058 (2017)
Feedback reports (ARF)5965 (2010)
Automatic responses3834 (2004)
Role mailbox names (postmaster, abuse)2142 (1997)
S/MIME, OpenPGP8551 (2019), 9580 (2024)

Final exam: questions

Answer each question out loud without looking anything up, then compare with the answers below. The goal: at least 45 out of 50.

How email works

  1. Tell the whole journey of a message from Alice’s mail app to Bob’s inbox, with every role, protocol and port.
  2. What is the difference between the envelope and the headers? Give two features that depend on the difference.
  3. What is the difference between ports 25, 587 and 465?
  4. Why might an email arrive hours late without anything being broken?
  5. Which headers does a receiving server add, and in what order should you read Received headers?
  6. Draw the MIME tree of a message with a plain-text version, an HTML version with an embedded logo, and a PDF attachment.
  7. Why does a 15 MB attachment exceed a 20 MB limit, and what do quoted-printable and base64 each suit?
  8. Type the SMTP commands of a complete transaction, in order. What does 250 ... queued as mean?
  9. What does a sending server do with a 451, and with a 550? Why does getting this wrong cause problems in both directions?
  10. What is backscatter, and how does a well-configured server avoid producing it?

DNS, servers and hosting

  1. How does a sender choose among MX records? What happens if a domain has no MX at all?
  2. Name two things an MX record must never point to.
  3. What is FCrDNS, why does it matter, and where do you set a PTR record?
  4. What are the IMAP sequence number, UID and UIDVALIDITY, and what happens to clients when UIDVALIDITY changes?
  5. Why did Google and Microsoft turn off basic authentication, and what replaced it?
  6. In Postfix, what’s the difference between smtpd_ and smtp_ settings, and which setting keeps a server from being an open relay?
  7. Why does a production server hand final delivery to Dovecot over LMTP?
  8. List the steps of a safe migration from one email provider to another.

Sender authentication

  1. Which domain does SPF check, and which address doesn’t it check?
  2. What’s the difference between -all, ~all and +all?
  3. What is the SPF lookup limit, which terms count, and what happens when you exceed it?
  4. Why does forwarding break SPF, and what are SRS and ARC?
  5. What do d=, s=, h=, bh= and b= mean in a DKIM signature?
  6. Where is a DKIM public key published, and how do you rotate a key safely?
  7. What’s the difference between simple and relaxed canonicalization?
  8. Name three things that commonly break DKIM signatures in real life.
  9. When does DMARC pass? Explain alignment, relaxed and strict.
  10. A message passes SPF and DKIM but fails DMARC. How is that possible, and how do you fix it?
  11. What changed in DMARC with RFCs 9989, 9990 and 9991?
  12. Describe a safe DMARC rollout from no record to p=reject.
  13. What do aggregate reports contain, and how do you recognize a spoofing source in one?
  14. What problem do MTA-STS and DANE solve, and how do they differ?

Deliverability, spam and troubleshooting

  1. Describe the stages of a spam filter. Which signals matter most at the big mailbox providers?
  2. Name five causes of spam placement that have nothing to do with the words in the message.
  3. What are the Gmail, Yahoo and Outlook.com bulk sender requirements, and since when?
  4. How does RFC 8058 one-click unsubscribe work, and why must a GET request not unsubscribe anyone?
  5. What is IP warm-up and how do you do it?
  6. What are the three kinds of spam traps, and what does hitting each one say about your list?
  7. How do you check whether an IP is on a DNS blocklist, and why might Spamhaus not answer you?
  8. A user says “I didn’t get an email from a customer”. What do you check, in order?
  9. A message took 20 minutes to arrive. How do you find out where it waited?
  10. What do 550 5.1.1, 550 5.7.26 (Gmail) and 550 5.7.515 (Outlook.com) mean?

HTML, images, code, security and administration

  1. Why are tables still used for email layout, and what does Gmail do to a message over about 102 KB?
  2. Compare hosted images, CID images and data URIs. Which would you use for a newsletter, a receipt’s logo, and never?
  3. Why must an email still work with images off, and what does Apple Mail Privacy Protection do to open tracking?
  4. Why should an application never send email inside the web request, and how should it retry failures?
  5. How should a website’s contact form send email, and why?
  6. Name the four ways to fake a sender and what stops each one.
  7. What does S/MIME protect, and what stays visible in an encrypted message?
  8. List the steps of offboarding a user’s mailbox.

Final exam: answers

  1. Alice’s MUA submits to her provider’s MSA over SMTP on 587 (STARTTLS) or 465 (TLS) with authentication. The MTA queues the message, DKIM-signs it, looks up the MX of example.net in DNS, and relays it with SMTP on port 25 to Bob’s MX, using STARTTLS. The MX checks reputation, SPF, DKIM, DMARC and content, the MDA (often over LMTP) stores it in Bob’s mailbox, and Bob reads it over IMAP on 993 or an HTTPS API.
  2. The envelope (MAIL FROM, RCPT TO) is part of the SMTP conversation and is what servers route by; the headers (From, To, …) are inside the message and are what people see. Bcc (recipients only in the envelope) and bounces to a list’s or ESP’s own address (a different MAIL FROM) depend on the difference.
  3. 25 is server to server, without user authentication. 587 is submission: plaintext, then STARTTLS, then AUTH. 465 is submission with TLS from the first byte.
  4. The receiver may be greylisting or rate limiting (answering 4xx), so the sender’s queue retries later, possibly for hours; or the sender’s queue itself is delayed.
  5. Return-Path, Delivered-To/X-Original-To, a Received header per hop, and filter headers such as Authentication-Results. Read Received headers from the bottom (oldest) up.
  6. multipart/mixed containing multipart/related (containing multipart/alternative with text/plain and text/html, plus image/png with a Content-ID) and application/pdf with Content-Disposition: attachment. Equally common: alternative on the outside, with related wrapping only the HTML and the image.
  7. Base64 makes data about 33% bigger, so 15 MB becomes about 20 MB plus line breaks and headers. Quoted-printable suits mostly-ASCII text (stays readable); base64 suits binary data and non-Latin text.
  8. EHLO, MAIL FROM:<...>, RCPT TO:<...> (one per recipient), DATA, the message, a line with a single dot, QUIT. 250 ... queued as means the server stored the message and took responsibility for it.
  9. 451: keep the message and retry later. 550: stop and bounce. A server that gives 5xx for a temporary problem loses mail; one that gives 4xx for a permanent problem makes senders retry for days and delays the bounce.
  10. Bounces sent to forged sender addresses after accepting a message. Avoid it by rejecting bad recipients, spam and viruses during the SMTP session, so the sending server generates any bounce.
  11. Lowest preference first, random among equal preferences, trying each address; on failure or 4xx, the next MX; if all fail, queue and retry. With no MX, senders fall back to the domain’s A/AAAA record (implicit MX), which is why domains that don’t receive mail should publish a null MX.
  12. An IP address and a CNAME.
  13. Forward-confirmed reverse DNS: the IP’s PTR name resolves back to the same IP. Receivers (Gmail requires it) penalize or reject IPs without it. The PTR is set by whoever owns the IP block: your hosting or cloud provider’s console or support.
  14. The sequence number is a message’s position and changes when earlier messages are removed; the UID is stable while UIDVALIDITY stays the same. If UIDVALIDITY changes (for example after a server migration), clients discard their cache and download everything again.
  15. Stored passwords can’t do MFA and give full access when stolen. OAuth 2.0 (XOAUTH2/OAUTHBEARER) replaced it, with app passwords as a limited exception at Google.
  16. smtpd_ settings are for receiving, smtp_ for sending. smtpd_relay_restrictions (permit trusted networks and authenticated users, reject unauthorized destinations) prevents open relaying.
  17. So that the mailbox server stores the message itself: indexes stay correct, Sieve filters and quotas apply, and the MTA gets an immediate per-recipient answer.
  18. Inventory (mailboxes, aliases, groups, senders); set up users and verify the domain at the new provider; publish the new provider’s DKIM and add it to SPF; lower TTLs; pre-stage copy; switch MX at a quiet time; delta sync; switch autodiscover and clients; keep the old system receiving and syncing for one to two weeks; then remove the old provider from SPF and DKIM, raise TTLs, and decommission.
  19. The domain of the envelope sender (MAIL FROM, or the HELO name for bounces). It does not check the From header.
  20. -all: fail anything not listed. ~all: softfail, suspicious but not rejected on SPF alone. +all: pass everyone, which makes the record worthless and dangerous.
  21. Ten DNS lookups in total, counting include, a, mx, ptr, exists and redirect (recursively); plus at most two void lookups. Exceeding it gives a permerror, which counts as no valid SPF.
  22. The forwarder’s IP isn’t in the original domain’s SPF record. SRS rewrites the envelope sender to the forwarder’s domain so SPF passes; ARC lets intermediaries record and sign the authentication results they saw, so receivers that trust them can accept the message even if SPF and DKIM no longer pass.
  23. d= the signing domain, s= the selector, h= the signed headers, bh= the hash of the body, b= the signature over the headers.
  24. At <selector>._domainkey.<domain> as a TXT record (or a CNAME to a provider’s key). Rotate by publishing a new selector, switching signing to it, keeping the old key for about a week, then publishing it with an empty p=.
  25. Simple tolerates (almost) no change; relaxed lowercases header names, collapses whitespace and unfolds headers, and ignores whitespace changes and trailing empty lines in the body. Use relaxed/relaxed.
  26. Mailing lists adding subject tags or footers; disclaimers or banners added after signing; gateways rewriting links; re-encoding of 8-bit content; a broken or truncated DNS key.
  27. When SPF or DKIM passes for a domain that aligns with the From domain. Relaxed: the same organizational domain. Strict: exactly the same domain.
  28. Both passed for a domain that doesn’t align with From, typically an ESP’s own domains. Fix: DKIM signing with d= your domain and a custom return-path under your domain at the ESP.
  29. DMARC became a Standards Track protocol in three documents (protocol, aggregate reports, failure reports); pct, rf and ri became historic; t=y (testing) replaces the common use of pct; np and psd were added; a DNS tree walk replaced the Public Suffix List.
  30. Publish p=none with rua; collect two to four weeks of reports; make every legitimate sender align (DKIM, return-path, SPF); move to p=quarantine (with t=y first if you want); then p=reject with sp and np; keep reading reports.
  31. Per source IP: message counts, SPF and DKIM results with their domains, the DMARC result and disposition. A spoofing source sends your domain in From from IPs you don’t recognize, with no aligned SPF or DKIM, often with a lookalike envelope domain.
  32. They stop the downgrade of server-to-server TLS (stripping STARTTLS, fake certificates). MTA-STS publishes a policy over HTTPS that senders cache and validates certificates with public CAs; DANE pins the certificate or key in DNSSEC-signed TLSA records.
  33. Connection (IP reputation, blocklists, PTR), SMTP dialogue (HELO, sender, recipient, TLS), authentication (SPF, DKIM, DMARC, ARC), content (links, attachments, HTML), reputation and engagement. At the big providers, domain and IP reputation and user engagement matter most.
  34. Any five of: missing or unaligned authentication; a blocklisted IP; no or generic PTR; a new IP or domain without warm-up; high complaint rate; spam trap hits; high bounce rate; volume spikes; low engagement; bad link-domain reputation; no TLS.
  35. Gmail and Yahoo since February 2024 (Gmail tightened enforcement from November 2025): for bulk senders, SPF and DKIM, DMARC (at least p=none) with alignment, one-click unsubscribe honored within two days, spam rate under 0.3%, plus PTR, TLS and RFC-compliant messages. Outlook.com since 5 May 2025 for senders of more than 5,000 messages a day: SPF, DKIM and DMARC, with junk filing and then 550 5.7.515 rejections.
  36. The message carries List-Unsubscribe with an HTTPS URL and List-Unsubscribe-Post: List-Unsubscribe=One-Click, both DKIM-signed; the provider sends a POST with that body, and the sender unsubscribes the recipient without any further step. Scanners and previews fetch URLs with GET automatically, so a GET must not unsubscribe.
  37. Gradually increasing volume from a new IP or domain over a few weeks, starting with the most engaged recipients, watching deferrals, bounces and complaints, and holding or stepping back when they rise.
  38. Pristine (never used by a person: you collected addresses without consent), recycled (abandoned addresses turned into traps: your list is old), typo (misspelled domains: you don’t validate or confirm sign-ups).
  39. Reverse the IP’s octets and look up <reversed>.zen.spamhaus.org; an answer in 127.0.0.x means listed (127.0.0.2 is the test entry). Spamhaus refuses queries from large public resolvers, so use your own resolver or their website.
  40. Spam folder, quarantine and the user’s rules; then the message trace for the sender in that time window; then ask the sender for the bounce or their log line with the remote 250; then check your MX records, availability and certificates.
  41. Get the headers of the delayed message and compare the time stamps of consecutive Received headers, converted to one time zone; the big gap shows where it waited (the sender’s queue, greylisting, a filter, final delivery).
  42. 5.1.1: the recipient doesn’t exist. Gmail 5.7.26: the message is unauthenticated or failed the From domain’s DMARC policy. Outlook.com 5.7.515: the sending domain doesn’t meet Microsoft’s authentication requirements for high-volume senders.
  43. Classic Outlook for Windows renders with Word’s engine, which doesn’t support modern CSS layout. Gmail clips the message behind a “View entire message” link, hiding the rest, including the unsubscribe link.
  44. Hosted: tiny messages, can be blocked until allowed, enable open tracking. CID: embedded in the message, shown without prompts, makes the message bigger. Data URIs: inside the HTML, not shown by Gmail or Outlook. Newsletter: hosted; receipt logo: CID (or a small hosted image); never: data URIs.
  45. Many clients and companies block external images by default, and some people turn them off; image-only mail is unreadable, inaccessible and looks like spam. Apple MPP preloads remote images through a proxy, so “opens” are recorded whether or not the person opened the message.
  46. Sending is slow and the relay can fail, so the request would be slow or lose the email. Queue a job and send from a worker; retry 4xx and network errors with exponential backoff and jitter, don’t retry permanent recipient errors, stop and alert on authentication or policy errors, and make sending idempotent.
  47. From your own address, to your own inbox, with the visitor’s address in Reply-To, never in From: a visitor’s From would fail DMARC and turns the form into a spam relay. Add rate limits and a CAPTCHA.
  48. Exact-domain spoofing (stopped by DMARC p=reject), lookalike domains (monitoring, filters, training), display-name spoofing (impersonation filters, external banners), compromised accounts (process controls such as call-back verification, MFA on the other side).
  49. Signing proves who sent the message and that it wasn’t changed; encryption keeps the content readable only by the recipient. From, To, Subject (in most implementations), dates and sizes stay visible.
  50. Block sign-in and revoke sessions; give a delegate access or convert to a shared mailbox; set an auto-reply (avoid forwarding, or forward internally for a short time); apply retention or holds; remove from groups and external systems; remove the license; delete only after the policy’s waiting period.

The complete checklist: what I can do without documentation

  • Draw the path of an email with every role, protocol and port, and explain the envelope.
  • Read a raw message: headers, Received chain, MIME tree, encodings.
  • Type SMTP, IMAP and POP3 sessions by hand, with STARTTLS and AUTH.
  • Interpret reply codes and bounces, and follow a message through MTA logs.
  • Publish and verify MX, PTR, SPF, DKIM, DMARC, MTA-STS, TLS-RPT and null MX records.
  • Run a Postfix and Dovecot server, its queue and logs.
  • Set up a domain on Google Workspace or Microsoft 365, and migrate a domain safely.
  • Count SPF lookups, sign and verify DKIM, and read DMARC aggregate reports.
  • Roll a domain to DMARC p=reject without losing legitimate mail.
  • Explain why a given message went to spam, and fix authentication, reputation, content and list problems.
  • Meet the Gmail, Yahoo and Outlook.com sender requirements, including one-click unsubscribe.
  • Troubleshoot delays, bounces and missing mail with headers, logs and message traces.
  • Build HTML email that renders everywhere, and use hosted and CID images correctly.
  • Send email from code with queues, retries, suppression lists and safe testing.
  • Defend against spoofing, phishing and BEC, and respond to a compromised mailbox.
  • Run mailboxes, retention, offboarding and monitoring for an organization.

Roadmap: what to learn next

  • The standards themselves. Read RFC 5321 and RFC 9989 end to end once; most “mysteries” are answered there.
  • M3AAWG (the Messaging, Malware and Mobile Anti-Abuse Working Group) publishes free best-practice documents on sending, DKIM key rotation, IPv6 mail and more, written by the people who run the largest mail systems.
  • Your provider’s admin tooling in depth: Exchange Online PowerShell and Microsoft Purview, or Google Workspace’s Admin console, Email Log Search and Vault.
  • Rspamd in depth: modules, Bayes, fuzzy hashes, and writing your own rules.
  • Run a real mail server for a small domain for a few months (a family or a hobby project), with DMARC reports and TLS-RPT turned on. Nothing teaches deliverability faster.
  • Email security operations: phishing analysis, sandboxing, and how attackers’ kits work.
  • Networking beneath it all: the Networking & the Internet course on this site covers DNS, TLS and TCP in the same hands-on style.