DomainKeys Identified Mail (DKIM) is an email authentication standard defined in RFC 6376. The sending server signs each message with a private key and adds the signature as a DKIM-Signature header. The receiving server fetches the matching public key from the signing domain’s DNS and checks the signature. A valid signature proves that the domain in the signature took responsibility for the message and that the signed headers and body were not changed in transit.
How DKIM Works
Signing
The sending server, usually the MTA, does the following for each message:
- Hash the body: It hashes the message body and stores the result in the
bh=tag. - Pick the headers: It lists the headers it signs, such as From, To, Subject and Date, in the
h=tag. The From header must always be signed. - Sign: It signs the body hash and the listed headers with the private key and stores the result in the
b=tag. - Name the key: It adds the signing domain in
d=and the selector ins=, so the receiver knows where to find the public key.
Verification
The receiving server reads d= and s=, queries a TXT record at <selector>._domainkey.<domain>, and checks the signature with the public key it finds there. The result is recorded in the Authentication-Results header as dkim=pass or dkim=fail.
DKIM Record and Signature Examples
The DNS Record
The public key is published as a TXT record under the selector:
esp1._domainkey.example.com. IN TXT "v=DKIM1; k=rsa; p=<public key>"
- v=DKIM1: The record version.
- k=rsa: The key type.
- p=: The base64 public key. An empty
p=means the key was revoked.
The Signature Header
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=esp1;
h=from:to:subject:date:message-id; bh=<body hash>; b=<signature>
The c= tag sets canonicalization. relaxed tolerates small whitespace and header case changes that some servers make in transit. simple tolerates almost none.
Selectors and Key Rotation
A selector lets one domain publish several keys at once. Each sending service, or each key generation, gets its own selector. To rotate a key, publish the new key under a new selector, switch signing to it, and remove the old record after mail signed with it has been delivered.
RFC 8301 requires rsa-sha256 and RSA keys of at least 1024 bits, and recommends 2048 bits. A DNS TXT string holds at most 255 characters, so a 2048-bit key is published as several quoted strings inside one record. Some DNS panels and checkers handle that badly, which is one reason ESPs often ask customers to publish a CNAME to a key the ESP hosts.
What DKIM Does Not Do
- It does not set a policy. DKIM reports pass or fail. It does not tell the receiver to reject a failed message. That is the job of DMARC.
- It does not check the From domain. The
d=domain can differ from the address the reader sees. DMARC requires the two to align. - It does not survive every change. A mailing list that adds a footer or rewrites the subject breaks the signature.
DKIM and Bulk Sender Rules
Gmail, Yahoo and Microsoft require DKIM from bulk senders. Gmail and Microsoft set the line at about 5,000 messages a day, and Microsoft requires both SPF and DKIM to pass for those senders (Gmail sender guidelines, Microsoft high-volume sender requirements). DKIM is also the check that most often carries DMARC, because it keeps working when the return-path domain belongs to the sending service.
Setting Up DKIM
- Generate a key pair: Use the DKIM generator or your MTA’s key tool. Keep the private key on the sending server only.
- Publish the public key: Add the TXT record under your selector, for example
esp1._domainkey.example.com. - Turn on signing: Configure the MTA to sign with
d=set to your From domain ands=set to the selector. - Test: Check the record with the SPF and DKIM checker, then send to a Gmail address and read the
Authentication-Resultsheader.
An ESP that sends for many customer domains signs each customer’s mail with that customer’s domain. The sender domain authentication guide shows a record layout for that. For how DKIM fits with the other two standards, read SPF vs DKIM vs DMARC.
DKIM ties each message to a domain with a signature that receivers can check. On its own it proves who signed the mail. Together with SPF and DMARC it lets receivers decide what to do with mail that fails.