Software & Internet

How Email Works: SMTP, SPF and DKIM Explained

Email moves between servers using SMTP, and SPF, DKIM and DMARC are the checks that help receivers judge whether a message really came from the domain it claims.

A laptop showing code on a white desk

Email works by handing a message from one server to another using the Simple Mail Transfer Protocol (SMTP) until it reaches the recipient’s mailbox. Because SMTP was designed without a way to prove who is sending, three add-on checks (SPF, DKIM and DMARC) now let receiving servers test whether a message really comes from the domain it displays.

How does email work from send to inbox?

When you press send, your mail app or webmail hands the message to an outgoing mail server run by your provider. That server is often called a mail transfer agent, or MTA: software whose job is to move messages onward. It reads the domain after the @ in each recipient address and asks the Domain Name System (DNS), the internet’s public directory, which servers accept mail for that domain. The answer comes from DNS records called MX records, short for mail exchanger. Our explainer on how DNS works covers that lookup layer in more detail.

The sending server then opens a connection to one of the servers named in those records and delivers the message using SMTP. The receiving server may pass it on again, run it through spam and malware filters, and finally store it in the recipient’s mailbox. If a server cannot deliver straight away, it generally holds the message and retries, which is why email is described as a “store and forward” system.

SMTP covers sending and relaying. Reading mail on your phone or laptop typically uses a separate protocol between your app and your own provider’s mailbox server. That is why a person can read mail from several devices while the servers between organizations only ever speak SMTP to each other.

All of this runs on the wider network plumbing described in how the internet works: addresses, routing and DNS.

What does SMTP actually say between servers?

SMTP is a short, text-based conversation. The sending server introduces itself, names the sender address, names each recipient, and then transmits the message content. The receiving server replies to each step with a status code that says to continue, to try again later, or that it refuses the message.

Two details matter for everything that follows:

  • The envelope and the header are separate. The envelope is the sender and recipient information given during the SMTP conversation, much like the details on the outside of a paper envelope. The header is the set of lines inside the message, including the From line your mail app displays. Nothing in basic SMTP forces the two to match.
  • Basic SMTP does not verify the sender. A server can claim any sender address. That is the gap that spoofing, meaning forging a sender’s identity, exploits.

Encryption is a different question from identity. The NCSC, the UK’s National Cyber Security Centre, advises that an email service should be able to send and receive mail using Transport Layer Security (TLS), which protects messages while they travel between servers. TLS does not tell you whether the sender is who they claim to be.

Why was email so easy to forge?

Early email networks were small and relatively trusting, so the protocol did not include sender verification. The visible From line is simply text that the sending software fills in. A criminal can therefore write a message that appears to come from a bank, an employer or a government department.

The NCSC frames the defenses as a way to make it difficult for fake email to be sent from your organization’s domains, and says securing domains also helps protect the people and organizations you deal with. Forged messages are a common ingredient in scams, covered in our guide to what phishing is and how to spot it.

What does SPF check?

SPF stands for Sender Policy Framework. According to the NCSC, a domain owner publishes in public DNS a list of the IP addresses trusted to send email for that domain. A receiving server compares the IP address of the server that delivered the message against that list. If the address is not on it, the receiver handles the message according to the domain’s published policy.

An SPF record is a line of text in DNS. The NCSC gives illustrative examples such as one that includes a Google record and ends with a “soft” instruction. In plain terms, the record says “mail from these providers is legitimate,” followed by a stance on everything else.

SPF has practical limits that the NCSC points out:

SPF limit What it means
10 DNS lookups SPF caps lookups at 10 to protect receiving servers. Nested “include” entries count toward the total.
450 bytes A record must be 450 bytes or fewer, counting spaces.
Subdomains Splitting services across subdomains gives each its own 10-lookup allowance.
Typing errors The syntax is sensitive to whitespace, and a missing space between terms is a common mistake.

Another limitation is that SPF looks at the server that delivered the message, not at the visible From line. The NCSC notes that DKIM can handle forwarded email, which is a case where SPF checks on the forwarding server may not line up with the original sender.

How does DKIM prove a message was not changed?

DKIM stands for DomainKeys Identified Mail. The NCSC describes it as attaching a cryptographic signature to outgoing email to show it came from your domain. In simple terms:

  1. The sending service signs the message using a private key that only the domain’s mail system holds.
  2. The domain publishes the matching public key in DNS, at a name built from a “selector” and the domain. The NCSC gives the format as the selector followed by “_domainkey” and then the domain.
  3. The receiving server fetches the public key and checks the signature. A match shows the message was signed by someone holding the private key and that the signed parts were not altered on the way.

The NCSC guidance makes several practical points. A signature should be the last addition to a message before the server releases it, so disclaimers and footers must be added first. Changing the body or headers after signing breaks the signature. It recommends a 2048-bit RSA key and suggests rotating keys about every 12 months, by creating a new key with a new selector and keeping the old DNS record live for a few days. DKIM keys do not expire on their own.

A valid signature shows that a domain vouches for a message. It does not mean the content is honest or safe, since criminals can sign mail from domains they own.

Where does DMARC fit in?

DMARC, short for Domain-based Message Authentication, Reporting and Conformance, ties the pieces together. The NCSC describes it as a policy that tells receiving servers what to do with email that fails SPF or DKIM checks, including discarding untrusted messages, and as a source of reports on how your email is handled.

The key idea is alignment. The domain in the visible From address should match the domain that passed SPF or DKIM. The NCSC explains that relaxed alignment, the default, lets a subdomain match its parent, while strict alignment requires an exact match. Without alignment, a criminal could pass SPF using their own domain while displaying someone else’s name in the From line.

DMARC offers graduated policies. The NCSC recommends a staged rollout:

  • None: changes nothing about how recipients handle mail, so it does not stop spoofing. It is used to gather reports for at least two weeks, which typically start arriving within 24 hours of publishing the record, according to the NCSC.
  • Quarantine: suspect mail is marked as spam.
  • Reject: recipients are told to refuse mail that fails. The NCSC calls this the best way to prevent spoofing of your domains.

It also describes a percentage setting that applies the stricter policy to a share of mail first, with an example of 50 percent, and says many organizations move from quarantine to reject after about three months, monitoring reports for at least two weeks afterward.

A worked example of a message being checked

Consider an invented company, example-shop.test, that sends receipts through a third-party email service.

  1. The service delivers a receipt to a customer’s provider. The receiver looks up example-shop.test in DNS and finds an SPF list that includes the service’s addresses. The sending IP is on the list, so SPF passes.
  2. The message carries a DKIM signature made with a key tied to a selector. The receiver fetches the public key from DNS and the signature verifies.
  3. The receiver checks alignment. If the signing domain is example-shop.test, it matches the From address, so DMARC passes.
  4. Now suppose a scammer sends a message with a From address at example-shop.test from their own server. SPF fails for that domain, there is no valid signature, and alignment fails. If the domain publishes a reject policy, the receiver is told to refuse it.

If the shop’s email service signed using its own default domain instead of the shop’s, alignment would fail even for genuine receipts. The NCSC specifically warns that providers often sign with their own domain by default, which causes alignment failures.

What are the common mistakes and misconceptions?

  • “A pass means the email is trustworthy.” Passing checks shows the message is consistent with a domain’s published rules, not that the sender is honest. Look-alike domains can pass every check.
  • “SPF alone is enough.” SPF checks the delivering server, so it can break when mail is forwarded, and it does not examine the visible From line by itself.
  • Editing after signing. Scanners or disclaimer tools that alter a message after DKIM signing break the signature, so they must be configured to avoid this.
  • Exceeding SPF limits. Adding many services through nested includes can push a record past 10 lookups.
  • Staying on “none” forever. A monitoring-only policy provides data but does not block forged mail.
  • Forgetting forgotten senders. Marketing platforms, billing tools and old systems often send mail for a domain. The NCSC advises investigating any unrecognized sending systems and expecting several cycles of updates before SPF and DKIM work for every legitimate source.

What varies by provider and organization?

The three checks are published by domain owners but enforced by receivers, so results can vary. Different receiving providers may treat a failure differently, and a policy of reject is a request that receivers are expected to honor but that depends on their configuration. Cloud email suites each have their own setup screens; the NCSC advises configuring SPF, DKIM and DMARC on all of an organization’s domains, including those used with cloud email providers. The NCSC guidance discussed here was first published on 7 October 2019 as version 2.0, so administrators should check current provider instructions for exact record values. Individual users generally cannot set any of this: it is the domain owner’s job, though readers can check headers in their mail app to see whether a message passed.

Shorter-lived certificates, covered in our piece on TLS renewals, show a similar theme: email security is increasingly about automation and ongoing upkeep rather than one-off setup.

Why email security is a layered habit

Email still relies on a trusting protocol, with identity checks added around it. SPF tests the sending server, DKIM tests a signature, and DMARC decides what happens when they fail and reports back. None of them judge whether a message is wise to act on, so caution with unexpected links and requests remains necessary.

This article is general information, not a substitute for professional security advice.

Sources: National Cyber Security Centre