How to set up SPF, DKIM and DMARC for your domain

Add SPF, DKIM and DMARC records to your domain step by step, with record examples, the common mistakes and a free checker to confirm they work.

Published · DASTER

Last updated

To set up SPF, DKIM and DMARC, you add three kinds of DNS records where your domain's DNS is hosted: one SPF TXT record on the domain, the DKIM records your email service gives you, and one DMARC TXT record at _dmarc.example.com. Then you check them with a tool like the free email DNS checker and send a test message.

This post shows what each record looks like, the order to add them in, and the mistakes that send mail to spam even when the records exist.

Why do these records matter?

Mail servers ask your domain's DNS whether a message really comes from you. Without an answer, they have to guess, and a guess often means the spam folder. Large mailbox providers now expect bulk senders to have all three records, and many refuse or junk mail that fails them.

RecordNameWhat it says
SPFexample.com (TXT)Which servers may send mail for the domain
DKIM<selector>._domainkey...The public key that checks the signature on each message
DMARC_dmarc.example.com (TXT)What to do with mail that fails, and where to send reports

SPF and DKIM prove a message is allowed. DMARC checks that the domain they prove matches the domain in the From line, and tells receivers what to do when it does not.

  1. Find out who sends mail for your domain

    Before you write any record, list every service that sends email with your domain in the From address. A typical list:

    • your app's transactional email (sign-up, receipts, password resets);
    • your newsletter or marketing tool;
    • your team's mailboxes;
    • a help desk or invoicing tool that sends "on behalf of" your domain.

    Each one needs to be in SPF or sign with DKIM, or DMARC will flag its mail later. Missing a sender here is the most common reason a strict DMARC policy breaks real email.

  2. Add one SPF record

    SPF is a single TXT record on the domain itself. It starts with v=spf1, lists the senders, and ends with a rule for everyone else:

    TXT
    example.com.  TXT  "v=spf1 include:_spf.mail-one.example include:_spf.mail-two.example ~all"
    • include: pulls in a sender's own list. Each email service tells you its include value.
    • ~all (soft fail) marks other senders as suspicious. -all (hard fail) tells receivers to reject them. Start with ~all and move to -all once DMARC reports look clean.
    • ip4: and ip6: add your own server addresses, for example ip4:203.0.113.10.

    Two rules catch people out:

    • One SPF record per name. If your domain already has a v=spf1 record, add the new include: to it. Two SPF records make SPF fail for every message.
    • At most 10 DNS lookups. Every include, a, mx, exists and redirect counts, including the ones inside each include. Remove services you no longer use before you add new ones.
  3. Add the DKIM records

    DKIM signs each message with a private key that stays with your email service. You publish the public key in DNS, under a name made of a selector and _domainkey:

    TXT
    s1._domainkey.example.com.  TXT    "v=DKIM1; k=rsa; p=MIIBIjANBgkqh...IDAQAB"
    s2._domainkey.example.com.  CNAME  s2.dkim.mail-provider.example.

    Some services give you a TXT record with the key in it. Others give you CNAME records that point to a key they host, which lets them rotate the key without asking you. Copy the names and values exactly as the service shows them. If your DNS provider adds the domain to the end of names by itself, enter only s1._domainkey, or you end up with s1._domainkey.example.com.example.com.

    Each service that sends for you needs its own DKIM record, under its own selector.

  4. Add a DMARC record

    DMARC is one TXT record at _dmarc on your domain. Start in monitoring mode:

    TXT
    _dmarc.example.com.  TXT  "v=DMARC1; p=none; rua=mailto:dmarc-reports@example.com"
    • p=none delivers mail as before but asks receivers to report what passes and fails.
    • rua= is the mailbox for those daily reports. Use an address you read, or a reports inbox you set up for this.

    Leave it at p=none for two to four weeks. Read the reports, find senders you forgot in step 1, and fix their SPF or DKIM. Then tighten the policy in two steps:

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

    quarantine sends failing mail to spam. reject refuses it. Keep only one DMARC record at a time; the lines above are stages, not three records.

    A domain that never sends mail should say so. Publish v=spf1 -all on it and a DMARC record with p=reject, so nobody can send in its name.

  5. Check the records

    DNS changes usually show within minutes, but a resolver can keep the old answer until the record's TTL runs out. Then check what the world sees:

    Terminal
    dig +short TXT example.com
    dig +short TXT s1._domainkey.example.com
    dig +short TXT _dmarc.example.com

    Or type the domain into the free email DNS checker. It reads the SPF, DMARC and MX records, and the DKIM key when you give it a selector, then marks each one Pass, Check, Problem or Note and says what to change. It runs in your browser, needs no account and works for any domain.

    Last, send a real message to a mailbox you own and open its headers. Look for spf=pass, dkim=pass and dmarc=pass in the Authentication-Results line.

Common mistakes

  • Two v=spf1 records on the same name.
  • More than 10 lookups in SPF after adding one more service.
  • A DKIM record pasted with the domain twice, or with a line break inside the key.
  • DMARC set to p=reject on day one, before every sender passes.
  • DMARC left at p=none for good, which protects nobody.
  • Records added at the old DNS provider after the domain's nameservers moved.

How do I set this up for DASTER App email?

App email sends your app's sign-up, receipt and reset emails from a domain you verify. Open App email in your project, choose Turn on App email, then add your domain as a sender domain and open its page. It shows the DKIM, SPF and DMARC records to add, with their exact values. Add them at your DNS provider and choose Check records.

If your domain already has an SPF record, the page tells you which include: to merge into it instead of adding a second one. The DMARC record it suggests starts at p=none. Once SPF and DKIM are verified, you can send from any address on the domain over the HTTP API or SMTP, and every account can send 5,000 emails free every month. The free email API page lists the daily limits.

To put the same domain in front of an app, see Connect a domain.

DASTER is in testing and sign-up is waitlist-only. Join the waitlist and you get access 20 days after you join.

Questions about SPF, DKIM and DMARC

Do I need all three records?

Yes, if you send email from your domain. SPF and DKIM prove the mail is allowed, and DMARC ties them to your From address. Many receivers expect all three from anyone who sends in bulk.

Can I have two SPF records?

No. With two v=spf1 records on one name, SPF fails for every message. Merge them into one record with every include: in it.

What is a DKIM selector?

The label in front of ._domainkey in the record name. In s1._domainkey.example.com the selector is s1. Your email service picks it, and it lets one domain have several DKIM keys.

Should DMARC start at p=none?

Yes. Start with p=none and a report address, read the reports for a few weeks, fix the senders that fail, then move to quarantine and later reject.

How long do DNS changes take?

Most DNS providers publish a change within minutes. A resolver that cached the old answer keeps it until the record's TTL ends, so lower the TTL before a big change.

Does my domain need an MX record to send?

No. MX is only for receiving mail. A domain that only sends can work without one, but it still needs SPF, DKIM and DMARC.

Next steps