Articles & BlogBy 8 min read

For anyone who has wondered how a scam email can show their bank's real address. By the end you will be able to open the hidden header of any message you received and see whether the sender's domain vouched for it.

An email arrives from your bank. The name is right. The address after the name is right too, down to the last letter. And the bank never sent it.

That is possible because of a decision made when email was young: the system delivers what it is handed and does not check who is speaking. Three later additions, SPF, DKIM and DMARC, were bolted on to fix this. To see what they fix, you first need to see how a message moves.

A wide view down a long automated letter sorting line in a postal center, with hundreds of small bins in rows receiving stacks of envelopes, grey plastic trays on a conveyor below, and one worker in the distanceA letter sorting line at a Swiss Post mail center. Email servers do the same work: read the envelope, pass it on. Photo by Hadi, CC0, via Wikimedia Commons.

How does a message travel?

Four kinds of software handle your message, and the standards give each a short name.

TermStands forPlain meaning
MUAMessage User AgentYour mail app or webmail page
MTAMessage Transfer AgentA mail server that relays the message one hop closer
MXMail exchangerThe DNS record naming the server that accepts mail for a domain
SMTPSimple Mail Transfer ProtocolThe language mail servers speak to each other, on port 25

You press send. Your mail app hands the message to your provider's server. That server needs to know where mail for example.org goes, so it asks DNS for the domain's MX record. (DNS: The Internet's Phone Book covers those lookups.) The answer is a server name, and where there are several, the lowest preference number is tried first. Your provider's server connects to it and the two talk SMTP. The receiving server files the message in a mailbox, and the recipient's app collects it.

A diagram titled The path of a message. Four boxes in a row joined by arrows: your mail app, labeled MUA; the sending server, labeled MTA; the receiving server, labeled MTA; and their mail app, labeled MUA. The steps between them are labeled submit, then SMTP on port 25, then IMAP or POP. A dashed arrow runs from the sending server down to a box that reads DNS lookup: the MX record names the receiving server. Below, under the heading Every message carries two sender addresses, are two boxes. The first says on the envelope, MAIL FROM: servers use it, you never see it, and SPF checks this one. The second says in the message, the From line: this is what your mail app shows, and SMTP itself never checks it. A closing line says DMARC is the rule that ties the two together.Four hops, one DNS lookup, and two different sender addresses.

Why can the From line be forged?

Because a message has two sender addresses, and the one you see is the one nobody checked.

The SMTP standard, RFC 5321, says a piece of mail "contains an envelope and content." The envelope is what the servers use: a command named MAIL FROM gives a return address and RCPT TO gives the recipient. The content comes after, and it includes the header lines your mail app displays: From, To, Subject, Date.

A paper letter works the same way. The post office reads the envelope. The letterhead inside can say anything, and the sorting machine in the photograph will never open it to compare.

Nothing in SMTP requires the envelope sender and the From line to match, or requires either to be true. The standard is blunt about it: "SMTP mail is inherently insecure." The sender types both addresses, and the receiving server, by default, believes them.

What do SPF, DKIM and DMARC each check?

Each one lets the owner of a domain publish something in DNS that receiving servers can test a message against. All three live in TXT records, the free-text record type.

SPF (Sender Policy Framework, RFC 7208) is a list of the servers allowed to send mail for a domain. The receiving server looks at the address the connection came from and asks whether it is on the list.

example.com.   TXT   "v=spf1 ip4:192.0.2.10 include:spf.example.net -all"

This record says: mail for example.com may come from 192.0.2.10 or from whatever spf.example.net lists, and -all says to fail everything else. A softer ~all means "probably not allowed."

DKIM (DomainKeys Identified Mail, RFC 6376) is a signature. The sending server signs the body and chosen header lines with a private key and adds a DKIM-Signature header that names the signing domain (d=) and a selector (s=), which says which key was used. The matching public key sits in DNS.

sel1._domainkey.example.com.   TXT   "v=DKIM1; k=rsa; p=MIGfMA0G...AQAB"

This record publishes the public key for selector sel1. If the message was changed after signing, the check fails. (Encryption and Hashing in Plain Terms explains key pairs and signatures.)

DMARC (RFC 7489) closes the gap the other two leave open. SPF tests the envelope sender, which you never see. DKIM tests whichever domain signed. A scammer can pass both honestly, using a domain of their own, while the From line shows your bank. DMARC looks at the From line and demands that SPF or DKIM passed for a domain that matches it. That matching is called alignment.

_dmarc.example.com.   TXT   "v=DMARC1; p=quarantine; rua=mailto:dmarc-reports@example.com"

This record says: if a message claiming to be from example.com fails DMARC, treat it as suspicious, and send summary reports to that address.

A diagram titled Three checks at the receiving server. Three stacked bands. SPF asks: is the sending server's address on the list published by the envelope sender's domain? DKIM asks: does the signature on the message match the public key published by the signing domain, the d= value? DMARC asks: did SPF or DKIM pass for a domain that matches the From line, and if neither did, follow the domain's policy. Three arrows lead down from DMARC to three outcomes: p=none, deliver and report; p=quarantine, treat as suspicious; p=reject, refuse the message. A note says the policy applies only to mail that fails DMARC.SPF and DKIM each prove something about a domain. DMARC asks whether it is the domain you were shown.

CheckWhat it testsWhat breaks it
SPFThe sending server's address, against the envelope sender's domainForwarding: the forwarder's address is not on the list
DKIMA signature over the message, against a key in the signer's DNSChanges in transit, such as a mailing list adding a footer
DMARCWhether a passing SPF or DKIM domain matches the From lineBoth of the above failing at once

What do none, quarantine and reject mean?

The p= tag in a DMARC record is the domain owner's request for mail that fails.

PolicyWhat the owner is askingWhen it is used
p=noneTake no special action, only send me reportsWhile finding every system that sends your mail
p=quarantineTreat failures as suspicious, for example the spam folderOnce the reports look clean
p=rejectRefuse failures outrightWhen you are sure nothing real will fail

It is a request. RFC 7489 says receivers should make a best effort to follow it and may do otherwise. Still, publishing the records has stopped being optional for anyone who wants mail delivered. Google's sender guidelines say that since 1 February 2024 anyone sending to Gmail must set up SPF or DKIM, and anyone sending more than 5,000 messages a day must have all three.

Tip

If you run a domain, start at p=none with a rua address and read the reports for a few weeks. They show every server sending as you, including the newsletter tool and the invoicing system you forgot about. Move to quarantine and then reject only after those are fixed. A domain that sends no mail at all can publish v=spf1 -all straight away.

How do you read the results on a real message?

The receiving server writes down what it found in a header named Authentication-Results (RFC 8601). You can read it on any message in your inbox. In Gmail, Google's help page says to open the message, click More next to Reply, and choose "Show original." Other mail apps have a similar "view source" or "show headers" option.

Authentication-Results: mx.example.org;
    spf=pass smtp.mailfrom=example.com;
    dkim=pass header.d=example.com;
    dmarc=pass header.from=example.com

Read it left to right. mx.example.org is the server that did the checking, and it should be your own mail provider. spf=pass is followed by the envelope domain that was tested. dkim=pass is followed by the domain that signed. dmarc=pass is followed by the From domain. Here all three name example.com, so the domain you were shown really did vouch for this message.

Now the pattern to learn. If SPF and DKIM pass for one domain and header.from shows a different one, DMARC will read fail, and the From line was borrowed.

To see what a domain publishes, ask DNS yourself:

nslookup -type=TXT _dmarc.example.com

This prints the DMARC record for a domain. Put in the domain of a company that emails you. The records are public, and looking is harmless.

Watch out

A pass is not a promise that a message is safe. It proves the mail came from the domain in the From line, and nothing about whether that domain is honest. A scammer who registers a look-alike domain can pass all three checks for it. DMARC's own text says attacks on the display name are outside its scope. Read the domain letter by letter, then judge the message.

What to remember

  • A message has an envelope sender for servers and a From line for you. SMTP checks neither.
  • SPF: is this server allowed to send for the envelope domain?
  • DKIM: was the message signed by a domain, and is it unchanged?
  • DMARC: does a domain that passed match the From line? If not, apply the owner's policy.
  • none watches, quarantine sends to spam, reject refuses.
  • The verdicts are in the Authentication-Results header of every message you receive.
  • A pass proves which domain sent it. It does not prove the domain deserves your trust.

Tonight, open "Show original" on three messages: one from a bank, one newsletter, one from the spam folder. Compare the three verdicts in each. Then read Phishing, Vishing, Smishing: How the Message Gets In for the tricks that work even when every check passes.