SEO guide

How to set up SPF, DKIM and DMARC so your emails don't land in spam

SPF, DKIM and DMARC are three DNS records that prove to receiving servers that your email really comes from you. In this guide, you'll find out what each one does, how the records are written, which settings Gmail, Yahoo and Microsoft require and how to verify your setup step by step.

11 min readUpdated: October 27, 2026

In short

  • SPF lists the authorized servers, DKIM provides the email's signature, and DMARC says what to do with email that fails authentication.
  • A domain can have only one SPF record, and the record can trigger at most 10 DNS lookups; if either limit is exceeded, SPF doesn't work at all.
  • For DKIM, use a key of at least 1024 bits, preferably 2048; the selector is the s= value in the signature header.
  • Start DMARC with p=none and an rua= reporting address; once the reports are clean, move to a quarantine policy, then to reject.
  • Gmail and Yahoo since February 2024, and Microsoft since May 2025, have required bulk senders to have all three records.

What do SPF, DKIM and DMARC do?

An email has two sender addresses. The envelope sender (Return-Path or MAIL FROM) is used for delivery between servers and isn't visible to the user. The From: address in the header is the one the recipient sees; spoofed emails usually forge this one.

  • SPF (Sender Policy Framework, RFC 7208): the list of servers that may send email on behalf of your domain. The receiver compares the IP address of the server delivering the email with the SPF record of the envelope sender's domain.
  • DKIM (DomainKeys Identified Mail, RFC 6376): the sending server signs each email with its private key, and the receiver verifies the signature with the public key in DNS. A valid signature shows that the message wasn't altered in transit and that the domain in the signature takes responsibility for it.
  • DMARC (RFC 9989): requires the domain in the From: address to match the domain that passed SPF or DKIM, says what to do with emails that don't match and arranges for reports to be sent to you.

SPF and DKIM alone don't protect the From: address: a fraudster can pass SPF with their own domain and put your address in the From: line. DMARC's alignment rule closes this gap, which is why all three are set up together.

RFC 9989, published in May 2026, replaced RFC 7489, DMARC's original 2015 specification, and moved DMARC onto the IETF standards track. Your existing v=DMARC1 records keep working.

What do Gmail, Yahoo and Microsoft require?

In February 2024, Gmail and Yahoo introduced mandatory rules for anyone sending email to personal accounts. Google considers a sender that sends close to 5,000 or more emails to Gmail addresses within 24 hours from the same primary domain (including subdomains) a bulk sender; this status is permanent. Yahoo doesn't disclose a threshold.

What Gmail requires from all senders:

  • SPF or DKIM authentication,
  • a valid reverse DNS (PTR) record for the sending IP address, with an A or AAAA record for that name pointing to the same IP,
  • a TLS-encrypted connection,
  • a spam rate below 0.3% as reported in Postmaster Tools.

Additionally, from bulk senders:

  • both SPF and DKIM, plus a DMARC record with at least a p=none policy,
  • a From: domain aligned with the SPF or DKIM domain,
  • one-click unsubscribe in marketing emails (List-Unsubscribe and List-Unsubscribe-Post headers, RFC 8058) and a visible unsubscribe link in the body. Yahoo requires unsubscribe requests to be processed within 2 days.

Google recommends keeping your spam rate below 0.1%, and since November 2025, it has applied temporary and permanent rejections to non-compliant traffic. Since May 5, 2025, Microsoft has also required domains that send more than 5,000 emails a day to Outlook.com, Hotmail and Live addresses to pass SPF and DKIM and have an aligned DMARC record; non-compliant emails are rejected with the code 550 5.7.515. For details, see Google's email sender guidelines. Even if you send only small volumes, set up all three records: they make it harder for anyone to send spoofed email from your domain.

How do you create an SPF record?

SPF is a TXT record added to the root domain (@). It starts with v=spf1, lists the allowed sources and ends with an all that says what happens to sources not on the list:

v=spf1 include:_spf.google.com include:servers.mcsv.net ip4:203.0.113.25 ~all
  • include: adds another domain's SPF record; email services (corporate email, newsletter and CRM tools) give you this value.
  • ip4: and ip6: specify your own server's address directly and don't use up any DNS lookups.
  • a and mx allow the servers in your domain's A or MX records.
  • ~all (softfail) treats sources not on the list as "probably unauthorized", while -all (fail) asks for outright rejection. ?all says nothing; +all allows everyone, so never use it.

~all or -all?

Google recommends ~all, while Microsoft recommends -all together with DKIM and DMARC. RFC 9989 explains the difference: email from a domain using -all may be rejected by some servers at the very start of the SMTP session, so even a legitimate message that would pass DKIM never reaches DMARC evaluation and doesn't show up in reports. If your DMARC policy is quarantine or reject, ~all is enough. For domains that don't send email, the correct record is v=spf1 -all.

The one-record and 10-lookup rules

A domain can have only one SPF record. If there are two separate v=spf1 records, the result is permerror and SPF doesn't work at all. When adding a new service, don't create a new record; add an include: to the existing one.

According to RFC 7208, include, a, mx, ptr, exists and redirect can trigger at most 10 DNS lookups in total, and nested includes count too. Exceeding the limit also results in permerror. "Void" lookups that point to a nonexistent name are also limited to two. To reduce the count:

  • remove the include: values of services you no longer use,
  • write ip4: instead of a and mx for your own servers with static IPs,
  • don't use ptr; RFC 7208 says it should not be published,
  • move high-volume sending such as newsletters to a subdomain like bulten.ornek.com.tr; each subdomain has its own SPF record, and its lookup budget is counted separately.

A single TXT string can be at most 255 characters; long records are split into chunks, and receivers join the chunks back together without adding spaces. If you split a record by hand, watch out for spaces at the split point.

See your SPF record's include chain and how many DNS lookups it uses, all in one go.

Email DNS checker

What is DKIM, and how do you set up the selector and key?

With DKIM, the sending server generates a signature from the email's headers and body and writes it to the DKIM-Signature header. In this header, d= is the signing domain and s= is the selector. The receiver looks up the public key in the record at <seçici>._domainkey.<alan adı>:

google._domainkey.ornek.com.tr  TXT  "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOC…"

The selector lets you keep more than one key on the same domain. By default, Google Workspace uses the google selector, Microsoft 365 uses selector1 and selector2, and Yandex 360 uses mail; newsletter and CRM services provide their own selectors. Because each service signs with its own key, the records don't interfere with one another. If you don't know your selector, look at the s= value in the headers of an email sent from your own domain.

  • Key length: according to RFC 8301, an RSA key must be at least 1024 bits, and 2048 bits is recommended. Gmail requires at least 1024 bits and recommends 2048; choose 2048 if your control panel supports it. A key of this length exceeds 255 characters; if your panel doesn't split it automatically, enter the value as quoted chunks.
  • Key rotation: publish the new key under a new selector, switch signing to it and delete the old record a few days later. The two selectors in Microsoft 365 exist for exactly this kind of rotation.
  • The right domain: if the d= in the signature is the service's own domain (for example, your newsletter tool's), it won't help DMARC alignment even if DKIM passes. Turn on the service's option to sign with your own domain.

How do you write a DMARC record?

A DMARC record is a TXT record added at the _dmarc name under your domain. Its simplest, risk-free form only monitors and doesn't block any email:

_dmarc.ornek.com.tr  TXT  "v=DMARC1; p=none; rua=mailto:dmarc@ornek.com.tr"
TagWhat does it do?
v=DMARC1Required; must be the first tag in the record.
p=Policy: none only monitors, quarantine sends to the spam folder, reject rejects the message.
rua=The address aggregate reports are sent to. If you leave it out, you won't receive any reports.
sp=, np=Separate policies for existing and nonexistent subdomains.
adkim=, aspf=Alignment: r relaxed (default), s strict.
t=yTest mode: the policy is applied one level lower. In RFC 9989, it replaced the old pct= tag.
ruf=Per-message failure reports; only a few providers send them.

What is alignment?

To pass DMARC, at least one of SPF or DKIM must both pass and be aligned with the From: domain. With relaxed alignment, the same organizational domain is enough: a d=mail.ornek.com.tr signature is aligned for From: info@ornek.com.tr. With strict alignment (adkim=s), the names must match exactly. If a service passes SPF with its own domain (bounce.hizmet.com), SPF doesn't count as aligned; that's why setting up DKIM with your own domain is the safest approach for third-party senders.

How do you use rua reports?

Aggregate reports are XML files, usually compressed with gzip, that receiving providers typically send once a day. They show which IP addresses sent how many emails on your behalf, along with the SPF and DKIM results; they don't contain message content. Collect the reports in a separate mailbox and read them with a DMARC report analyzer. If the reporting address is on a different domain, that domain must publish a TXT record containing v=DMARC1 at ornek.com.tr._report._dmarc.<rapor-alanı>; otherwise receivers won't send reports to that address.

ruf= failure reports can contain the headers of individual emails and sometimes their content. Because they may include personal data, pay attention to who processes these reports from a KVKK perspective; in most cases, rua= is enough.

Sample records for Google Workspace, Microsoft 365 and Yandex

These records are written for ornek.com.tr. DKIM keys are unique to each domain; copy the value from the service's control panel. If you use more than one service, combine the SPF values in a single record.

Google Workspace

@                  TXT   v=spf1 include:_spf.google.com ~all
google._domainkey  TXT   v=DKIM1; k=rsa; p=…   (Yönetici konsolundan)
_dmarc             TXT   v=DMARC1; p=none; rua=mailto:dmarc@ornek.com.tr

In the Admin console, generate the DKIM key from Gmail's Authenticate email setting by selecting 2048 bits; after adding it to your DNS, start authentication from the same screen. Google notes that activation can take up to 48 hours.

Microsoft 365

@                     TXT     v=spf1 include:spf.protection.outlook.com -all
selector1._domainkey  CNAME   selector1-ornek-com-tr._domainkey.<kiracı>.<x>-v1.dkim.mail.microsoft
selector2._domainkey  CNAME   selector2-ornek-com-tr._domainkey.<kiracı>.<x>-v1.dkim.mail.microsoft
_dmarc                TXT     v=DMARC1; p=none; rua=mailto:dmarc@ornek.com.tr

In Microsoft 365, two CNAME records are added for DKIM. Get the exact values from the DKIM settings in the Microsoft Defender portal or with the Get-DkimSigningConfig command, then enable signing.

Yandex 360

@                TXT   v=spf1 redirect=_spf.yandex.net
mail._domainkey  TXT   v=DKIM1; k=rsa; p=…   (Yandex 360 yönetim panelinden)
_dmarc           TXT   v=DMARC1; p=none; rua=mailto:dmarc@ornek.com.tr

redirect= hands SPF evaluation over entirely to Yandex's record, which is why it doesn't contain all. If you also use a sender other than Yandex, switch to the format Yandex recommends: v=spf1 ip4:… include:_spf.yandex.net ~all.

Step-by-step setup and verification

  1. Take inventory. List everything that sends email using your domain: corporate email, website forms, newsletters, CRM, billing and support systems. Emails from a forgotten source will be rejected once you tighten the policy.
  2. Consolidate SPF into a single record and keep the number of DNS lookups under 10.
  3. Turn on DKIM for each sender with your own domain and a 2048-bit key.
  4. Publish DMARC: start with p=none and rua=.
  5. Test. In Gmail, open an email from your own domain and choose "Show original"; you should see PASS on the SPF, DKIM and DMARC lines. In other email clients, check the Authentication-Results line in the message headers.
  6. Monitor the reports for a few weeks. Fix legitimate sources that fail or show up as unaligned; sources you don't recognize are most likely spoofed mail.
  7. Tighten the policy: first p=quarantine (with t=y for a while if you prefer), then p=reject if no problems arise.
  8. Lock down domains that don't send email. For your domains that don't send email, publish v=spf1 -all and p=reject; if they don't receive email either, add a null MX record (RFC 7505).

How soon the new record is visible everywhere depends on the old record's TTL; if a test still shows the old record, try again a few hours later.

If your records are correct but emails still land in spam

  • Check the reverse DNS record of the sending IP address, and whether that name points back to the same IP, with IP address lookup.
  • Monitor your spam rate and your compliance with the sender requirements in Google Postmaster Tools.
  • Remove addresses that haven't given consent, have been inactive for a long time or bounce from your list.
  • SPF can break on forwarded emails, and DKIM on mailing lists that modify the subject or body; ARC (RFC 8617) lets intermediate servers carry the authentication results forward.
  • If you send commercial messages to consumers in Türkiye, having recipients' consent registered in the Message Management System (İleti Yönetim Sistemi, İYS) is also a legal obligation.

After adding the record, check whether public DNS servers are seeing the new value.

DNS propagation checker

What are MTA-STS, TLS-RPT and BIMI?

These three records are optional; they're the next steps once SPF, DKIM and DMARC are in place.

MTA-STS (RFC 8461) tells servers that send you email to connect to your MX servers only over TLS with a valid certificate, preventing man-in-the-middle attacks that downgrade encryption. It consists of a TXT record and a policy file served over HTTPS:

_mta-sts.ornek.com.tr  TXT  v=STSv1; id=20261027T000000

https://mta-sts.ornek.com.tr/.well-known/mta-sts.txt
version: STSv1
mode: testing
mx: mx1.ornek.com.tr
max_age: 604800

Start with mode: testing and switch to enforce if there are no problems; change the id= value every time you change the policy file. Verify the certificate of the mta-sts subdomain with the SSL certificate checker.

TLS-RPT (RFC 8460) reports encrypted delivery problems in a daily report: all you need to do is add the TXT record v=TLSRPTv1; rua=mailto:tlsrpt@ornek.com.tr at _smtp._tls.

BIMI lets your logo appear next to the sender name in the inbox. For Gmail, your DMARC policy must be quarantine or reject, the logo must be in SVG Tiny PS format, and you must obtain a VMC or CMC certificate. A VMC requires a registered trademark and displays a checkmark in Gmail; a CMC is for unregistered logos. The record is added at default._bimi:

default._bimi.ornek.com.tr  TXT  v=BIMI1; l=https://ornek.com.tr/logo.svg; a=https://ornek.com.tr/vmc.pem

Frequently asked questions

How do you create an SPF record?

Add a single TXT record starting with v=spf1 to your root domain, list the include values your email services give you and end the record with ~all or -all. If you use only Google Workspace, the record is v=spf1 include:_spf.google.com ~all.

What is DKIM?

DKIM is a digital signature that the sending server adds to each email. The receiver verifies the signature with the public key in your domain's DNS and can tell that the message wasn't altered in transit.

Why are my emails going to spam?

The most common cause is missing or incorrect SPF, DKIM and DMARC records, followed by sending IPs without a reverse DNS record, high spam complaint rates and lists built without consent. You can see which records are missing with the Email DNS checker.

I have two SPF records. Is that a problem?

Yes. If a domain has more than one v=spf1 record, SPF returns permerror and none of them is considered valid. Combine all your include and ip4 values into a single record.

Is a DMARC record mandatory?

It's mandatory if you send around 5,000 or more emails a day to Gmail and Outlook.com, and strongly recommended if you send fewer. The safest start is a record with a p=none policy, which blocks no email, and an rua reporting address.

Should I use ~all or -all in SPF?

Google recommends ~all, Microsoft -all. If your DMARC policy is quarantine or reject, ~all is enough and prevents legitimate emails that pass DKIM from being rejected early; use -all on domains that don't send any email.

Related guides and tools