SPF, DKIM, and DMARC cheat sheet for email authentication

This cheat sheet brings together the three records that authenticate the mail your domain sends: SPF, which sets which servers may send mail for the domain, DKIM, which signs every message, and DMARC, which sets what happens to a message that fails the checks. You'll find the syntax of each record, the Gmail, Yahoo, and Microsoft requirements for bulk senders, and fixes for common problems. You can search for a tag or mechanism, filter by topic, and copy with one click.

SPF: record structure and mechanisms

  • v=spf1

    Every SPF record starts with the version v=spf1 and is published as a TXT record on the domain name itself. The mechanisms follow the version, and the check runs through them from left to right, stopping at the first mechanism that matches the IP address of the sending server.

    Example: example.com. 3600 IN TXT "v=spf1 mx include:_spf.example.net -all"

  • ip4:192.0.2.0/24

    Authorizes a single IPv4 address or a range of addresses in CIDR notation. This mechanism needs no DNS lookup, so it doesn't count toward the 10-lookup limit.

    Example: v=spf1 ip4:192.0.2.25 ip4:198.51.100.0/24 -all

  • ip6:2001:db8::/32

    Authorizes an IPv6 address or range. A server that also sends mail over IPv6 must appear in the record with its IPv6 address too, or messages sent from that address fail the check.

  • a

    Authorizes the addresses in the domain's A and AAAA records. You can name another domain, for example a:mail.example.com. This mechanism counts as a DNS lookup.

  • mx

    Authorizes the domain's incoming mail servers, according to its MX records. Use it when the same servers also send mail. It counts as a DNS lookup, and each MX record may lead to no more than 10 addresses.

  • include:_spf.example.net

    Adds the authorized servers of another domain, usually a sending service or an email provider. Each include counts as a lookup, and so do the lookups inside the included record. An address that isn't in the included record doesn't fail right away; the check moves on to the next mechanism.

  • exists:%{i}._spf.example.com

    An advanced mechanism: it passes when the name built from the macro has an A record, for example a name based on the sender's IP address (%{i}). Large providers use it mainly for dynamic checks, and it counts as a lookup.

  • ptr

    The standard recommends against this mechanism: it's slow, less reliable, and puts load on DNS servers. Replace it with ip4, ip6, or a.

  • all

    Matches every address, so it goes at the end of the record and sets the result for any server not listed before it. Mechanisms after all are never checked.

SPF: qualifiers, modifiers, and results

  • -all

    The minus qualifier: a server that isn't listed gets the result fail, meaning it isn't authorized to send mail for the domain. Use it once all of the domain's sending services are in the record.

  • ~all

    The tilde qualifier: a server that isn't listed gets the result softfail, meaning suspicious. Common during a transition. On a domain with DMARC, both softfail and fail count as an SPF failure, and the DMARC policy decides what happens.

  • ?all

    The question mark qualifier: the result is neutral, and the domain asserts nothing about other servers. It's almost the same as having no record, so it doesn't protect the domain.

  • +all

    Caution: authorizes any server to send mail for the domain, which effectively turns off the protection. Don't use it. The plus is also the default qualifier of every mechanism, so mx and +mx are the same.

  • redirect=_spf.example.com

    A modifier that hands the check over to another domain's SPF record when no mechanism matched. Useful when several domains share one record. It counts as a lookup, and it's ignored when the record contains all.

    Example: v=spf1 redirect=_spf.example.com

  • exp=explain._spf.example.com

    A modifier that points to a TXT record with an explanation, which the receiving server may add to the rejection message when the result is fail. Rarely used.

  • pass fail softfail neutral none temperror permerror

    The check results: pass (authorized), fail (not authorized), softfail (suspicious), neutral (no assertion), none (no record), temperror (temporary DNS error), and permerror (invalid record). The result appears in the Authentication-Results header of the received message.

    Example: Authentication-Results: mx.example.org; spf=pass smtp.mailfrom=example.com

SPF: limits and common mistakes

  • include a mx ptr exists redirect

    The 10-lookup limit: these mechanisms and this modifier need a DNS lookup, and the whole check, including the included records, allows up to 10 lookups. Going over returns permerror, and the message is treated as if it didn't pass SPF. ip4, ip6, and all don't count.

  • void lookups

    Void lookups: a mechanism that points to a name with no records, for example an include for a service that has shut down. The standard recommends limiting them to two, and going over returns permerror. So remove services you no longer use from the record.

  • v=spf1 mx include:_spf.example.net include:mail.example.org -all

    Each domain may have only one SPF record, and two records that start with v=spf1 on the same name return permerror. When you add a sending service, add an include to the existing record instead of creating a new one.

  • "v=spf1 ip4:192.0.2.0/24 " "include:_spf.example.net -all"

    A string in a TXT record is limited to 255 characters. A longer record is split into several quoted strings, which are joined without a space, so leave a space at the end of the first string. The standard recommends keeping the whole response under 512 bytes.

  • v=spf1 -all

    A record for a domain that sends no mail at all. It keeps the domain from being used for spoofing, and it's best paired with a DMARC record with p=reject.

  • bounce.example.com

    An SPF record applies only to the name it's published on, not to its subdomains. A subdomain that sends mail, such as the return address of an email marketing service, needs its own SPF record.

  • Return-Path

    SPF checks the domain in the return address (MAIL FROM, shown in the Return-Path header), not the address the recipient sees in the From field. A sending service that uses its own return address passes SPF for its own domain, and DMARC is what checks whether the domains align.

DKIM: the key record

  • selector._domainkey.example.com

    The name of the key record is made up of a selector the sender chooses, the _domainkey label, and the domain name. The selector appears in every signature in the s= tag, so the receiving server knows which record to read. You can keep several selectors at once, for example a separate selector for each sending service.

    Example: s1._domainkey.example.com. 3600 IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA..."

  • v=DKIM1

    The record version. The tag is recommended but not required, and when it's present, it must come first.

  • k=rsa

    The key type, and the default is rsa. The recommended length is 2048 bits, and the minimum the standard allows is 1024 bits.

  • k=ed25519

    An Ed25519 key, much shorter than an RSA key. Not every receiving server verifies this kind of signature, so it's common to also sign with an RSA key, with a separate selector for each key.

  • p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...

    The public key, Base64 encoded. A 2048-bit RSA key is longer than 255 characters, so it's split into several strings in the same record. In most DNS management interfaces, you paste the key as is, and it's split automatically.

  • p=

    An empty p tag means the key was revoked, and signatures made with it fail verification. This is how you retire an old selector after rotating keys.

    Example: old._domainkey.example.com. 3600 IN TXT "v=DKIM1; p="

  • t=y

    Testing mode: the domain announces that it's testing DKIM, and the standard says receiving servers must not treat its messages differently from unsigned messages. Remove the tag when testing is done.

  • t=s

    Requires the domain in the signature's i= tag to be identical to the domain in the d= tag, not a subdomain of it.

  • s1._domainkey.example.com. CNAME s1.dkim.example.net.

    Some sending services ask you to set up a CNAME record on the selector name that points to a key they manage. This way, the service rotates keys without any change to the domain's DNS.

  • s2._domainkey.example.com

    Key rotation is done with a new selector: publish the new key under a new selector, switch signing to it, and keep the old record for a few days, until the messages signed with the old key have been delivered. Then revoke the old record with an empty p= or delete it.

DKIM: the signature in the message

  • DKIM-Signature

    A header the sending server adds to the message, with the signing domain, the selector, the list of signed headers, and the signature itself. Several signatures on the same message are normal, for example one from the domain and one from the sending service.

    Example: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=s1; h=from:to:subject:date; bh=...; b=...

  • d=example.com

    The signing domain. DMARC counts the signature only when this domain aligns with the domain in the From field, so a service that signs only with its own domain doesn't help your domain pass DMARC.

  • s=s1

    The selector. Together with d=, it sets the name of the key record, in this example s1._domainkey.example.com.

  • a=rsa-sha256

    The signing algorithm. rsa-sha256 is the common one, and ed25519-sha256 is used with Ed25519 keys. The standard forbids signing with rsa-sha1.

  • h=from:to:subject:date

    The signed headers. The From header must be signed, and a change to a signed header in transit makes the signature fail.

  • bh=

    A hash of the message body. If the body changed after signing, for example when a footer was added or a scan changed the content, you get the error body hash did not verify.

  • c=relaxed/relaxed

    The canonicalization method for the headers and the body. relaxed tolerates small whitespace changes, so it's recommended. simple, the default, fails on even a small change.

  • l=

    The length of the signed body. When this tag is present, content can be added after the signed part without the signature failing, so using it isn't recommended.

DMARC: the policy record

  • _dmarc.example.com

    A DMARC record is a TXT record named _dmarc under the domain, and each domain may have only one. A subdomain without a record of its own gets the policy of the main domain.

    Example: _dmarc.example.com. 3600 IN TXT "v=DMARC1; p=none; rua=mailto:dmarc@example.com"

  • v=DMARC1

    The record version, required and always first. A record that doesn't start this way isn't treated as a DMARC record.

  • p=none

    Monitoring policy: failing messages are accepted as usual, and the reports show who sends mail as the domain. This is the first stage of every rollout.

  • p=quarantine

    Failing messages are treated as suspicious and usually go to the spam folder.

  • p=reject

    Asks receiving servers to reject failing messages during delivery. This is full protection against spoofing of the domain, and you move to it once all legitimate sending services pass the check.

    Example: v=DMARC1; p=reject; rua=mailto:dmarc@example.com

  • sp=quarantine

    The policy for existing subdomains. Without this tag, subdomains get the policy in p.

  • np=reject

    The policy for subdomains that don't exist in DNS, which are sometimes used for spoofing. Without this tag, the policy in sp applies, or the one in p.

  • rua=mailto:dmarc@example.com

    The address for aggregate reports: receiving servers report how many messages came from each IP address and what the check results were. You can list several addresses separated by commas.

  • ruf=mailto:dmarc-failures@example.com

    The address for failure reports about individual messages. Some large email providers don't send these reports, so the aggregate reports are what matter most.

  • fo=1

    When to send failure reports: 0, the default, when neither SPF nor DKIM passed with alignment; 1 when SPF or DKIM didn't pass with alignment; d when the DKIM signature failed; and s when the SPF check failed.

  • adkim=s

    DKIM alignment: r (relaxed), the default, means the signing domain needs the same organizational domain as the sender address. s (strict) means the domains must be identical.

  • aspf=s

    SPF alignment: r (relaxed), the default, means the return address (Return-Path) domain needs the same organizational domain as the sender address. s (strict) means the domains must be identical.

  • t=y

    Test mode: asks receiving servers to apply one level below the policy, none instead of quarantine and quarantine instead of reject. It serves as an intermediate step on the way to a stricter policy, and it doesn't affect reports.

    Example: v=DMARC1; p=reject; t=y; rua=mailto:dmarc@example.com

  • psd=y

    Declares the domain a public suffix domain (PSD), a suffix under which different organizations register their domains. This value is meant only for the operators of such suffixes, and the default is u.

  • pct ri rf

    The pct, ri, and rf tags are marked as historic in the updated version of the standard (RFC 9989), and receiving servers that follow it ignore them. Instead of a gradual percentage rollout with pct, use the t=y tag. We recommend removing them from the record.

  • example.com._report._dmarc.example.net

    Report authorization record: when the report address in rua is in another domain, the domain that receives the reports must publish a TXT record with this name and the value v=DMARC1, or the reports won't be sent to it.

    Example: example.com._report._dmarc.example.net. 3600 IN TXT "v=DMARC1"

Checking the records from the command line

  • dig +short TXT example.com

    Shows the domain's TXT records, including the SPF record. Make sure there's only one record that starts with v=spf1.

  • dig +short TXT _dmarc.example.com

    Shows the domain's DMARC record.

  • dig +short TXT s1._domainkey.example.com

    Shows the DKIM key of the s1 selector. You find the selector name in the s= tag of the DKIM-Signature header of a message sent from the domain.

  • nslookup -type=TXT _dmarc.example.com

    The same check with nslookup, which is also available on Windows.

Gmail, Yahoo, and Microsoft requirements

  • Gmail

    All senders: SPF or DKIM, valid forward and reverse (PTR) DNS records for the sending addresses, a TLS connection, and a spam complaint rate below 0.3%. Senders of more than 5,000 messages a day to Gmail accounts: both SPF and DKIM, a DMARC record (p=none is enough), alignment of the From domain with SPF or DKIM, and one-click unsubscribe in marketing messages. Google recommends a complaint rate below 0.1% and a 2048-bit DKIM key.

  • Yahoo

    All senders: at least SPF or DKIM, valid forward and reverse DNS records, and a spam complaint rate below 0.3%. Bulk senders: both SPF and DKIM, a DMARC record with at least p=none that passes with alignment (relaxed alignment is enough), one-click unsubscribe, a visible unsubscribe link in the message body, and handling unsubscribe requests within two days.

  • Outlook.com

    Senders of more than 5,000 messages a day to Outlook.com, Hotmail, and Live addresses: SPF and DKIM that pass, and a DMARC record with at least p=none that aligns with SPF or DKIM, preferably both. Messages that don't meet the requirements may be rejected with the error 550 5.7.515.

  • List-Unsubscribe-Post: List-Unsubscribe=One-Click

    One-click unsubscribe (RFC 8058): the message includes a List-Unsubscribe header with an HTTPS URL, and this header as well. The email client sends a POST request to the URL, and the recipient is removed from the list without visiting the website. Both headers need to be signed with DKIM.

    Example: List-Unsubscribe: <https://example.com/unsubscribe/abc123>

Troubleshooting

  • spf=permerror

    Usually more than 10 lookups, two SPF records, or a syntax error. Remove includes for services you no longer use, merge everything into one record, and on servers you control, replace a and mx with fixed ip4 and ip6 addresses.

  • spf=fail

    The sending server isn't in the record. Check the Received headers to see which IP address the message left from, and add the service to the existing record. Automatically forwarded mail fails SPF by nature, because the forwarding server isn't in the sending domain's record.

  • dkim=fail (body hash did not verify)

    The message body changed after signing: a mailing list added a line at the bottom, a security scan rewrote links, or software changed the encoding. When it happens to every message, make sure signing is the last step before the message leaves the server.

  • dkim=permerror

    The receiving server couldn't use the key record, for example because the record is missing or invalid. Check the selector name against the s= tag, check that the record was added in the interface that actually manages the domain's DNS, and check that the key wasn't cut off when it was copied.

  • dmarc=fail

    The message passed SPF or DKIM, but for another domain, for example the domain of the email marketing service. In the service, set up DKIM signing with your domain, or a return address on a subdomain of yours, so the domains align with the From field.

  • forwarding

    Forwarded mail and mailing lists: SPF fails along the way, but the DKIM signature usually survives as long as the message isn't changed, so DMARC still passes. That's why it's important for all your mail to be signed with DKIM for your domain. A list that changes the subject or the body breaks the signature too, and some lists replace the sender address with the list's own address to pass DMARC.

  • ARC

    ARC (RFC 8617) lets a forwarding server or a mailing list record the authentication results as they were when the message reached it, so the receiving server can take them into account even if the message was changed along the way. ARC is implemented on the forwarding server, not on the sending domain, and Yahoo recommends that forwarding servers implement it.

How SPF, DKIM, and DMARC work together

SPF checks whether the server that sent the message is authorized to send mail for the domain in the return address. DKIM checks that the message was signed by the domain and wasn't changed in transit. DMARC ties them to the address the recipient actually sees, in the From field: a message passes DMARC if SPF passed for a domain that aligns with the From domain, or if it has a valid DKIM signature for such a domain. One of the two is enough.

Alignment is where most setups fail. With relaxed alignment, the default, news.example.com aligns with example.com, but the domain of the email marketing service doesn't. So every service that sends mail for you needs to sign with DKIM using your domain, or to use a return address on your domain.

Moving gradually to a reject policy

  • Monitor: publish p=none with a report address in rua, and collect reports for at least a few weeks.
  • Fix: find in the reports every service that sends mail as the domain, such as an email marketing system, an online store, and an invoicing system, and set up aligned SPF and DKIM for each one.
  • Tighten: move to p=quarantine. You can start with t=y as an intermediate step.
  • Full protection: when the reports show that all legitimate mail passes, move to p=reject. The standard recommends that a domain whose users post to mailing lists not move to reject.

Reading DMARC aggregate reports

The reports arrive as a compressed XML file, usually once a day from each email provider. For every IP address that sent mail as the domain, they show the number of messages, the SPF and DKIM results, whether they align with the domain, and the policy that was applied. An IP address you don't recognize is usually a legitimate service that hasn't been set up yet, or an attempt to spoof the domain. The reports don't include the content of the messages.

You can check the records from the command line with dig or nslookup, and split a long DKIM key into strings with the long TXT record splitter. Rejections from receiving servers are explained on the SMTP error codes page, and the ports for mail transfer and for sending from email clients are port 25, port 465, and port 587. The domains and addresses on this page are examples, so replace them with your real values.

Did you know?

With our business email service, the SPF record and DKIM signing are set up automatically for your business domain, and a DMARC record is set up on request.

Business email

SPF, DKIM, and DMARC FAQ

What's the difference between SPF, DKIM, and DMARC?

SPF is the list of servers authorized to send mail for the domain. DKIM is a digital signature attached to every message that proves it was sent from the domain and wasn't changed in transit. DMARC ties both of them to the address the recipient sees in the From field, and sets what happens to a message that fails: accept it, send it to the spam folder, or reject it. Together, the three make it very hard to spoof your domain and improve the chances that your messages reach the inbox.

Why do messages from my domain go to spam even though I set up SPF?

SPF alone isn't enough anymore. The large email providers also check the DKIM signature and the DMARC record, and they check that the domain in the From field aligns with the domain that passed the check. Send a message to your own mailbox and check its headers with the email header analyzer: the spf, dkim, and dmarc results in the Authentication-Results header show exactly what failed.

How do I add an email marketing service to an existing SPF record?

Add the include the service gives you to the existing record, before all, and don't create a second record, because two SPF records make the check fail. For example, the record v=spf1 mx -all becomes v=spf1 mx include:_spf.example.net -all. After the change, use the SPF record checker to make sure the record stays within the 10-lookup limit.

Is a DMARC record with p=none enough?

For the Gmail and Yahoo bulk sender requirements, a record with p=none is enough, and it's also the right first step, because the reports show who sends mail as your domain. However, p=none doesn't protect against spoofing. Once all your legitimate services pass, move to quarantine and then to reject. You can create the record with the DMARC record generator.

What does it take for bulk email to reach the Gmail and Yahoo inbox?

You need SPF and DKIM records for the sending domain, a DMARC record with at least p=none, and a domain in the From field that aligns with one of them. In addition, every marketing message needs to offer one-click unsubscribe, and the spam complaint rate needs to stay below 0.3%, preferably below 0.1%. A clean mailing list, where every recipient asked to receive your messages, is the safest way to stay under that threshold.

Shopping cart

Your cart is emptyYou can start with one of our popular plans.

Site search

Accessibility

Text size
100%
Accessibility statement