# SPF, DKIM & DMARC setup

> Authenticate your sending domain with SPF, DKIM, and DMARC so Gmail, Outlook, and Apple Mail trust your app's sign-in links and receipts.

- Canonical: https://exaspark.ai/docs/email-authentication-dns/

## Why inbox providers block unauthenticated app mail

Standard email protocols were never built with identity checks. Without DNS authentication, any server on the internet can claim a message came from `receipts@yourbrand.com`, leaving mailbox providers unable to separate legitimate payment confirmations from phishing attempts.

Major providers including Gmail, Yahoo, and Outlook now enforce strict authentication policies. Messages lacking valid **SPF**, **DKIM**, and **DMARC** records are routinely routed to Spam, stripped of active links, or rejected outright during SMTP handshakes.

On ExaSpark's **Free** plan (`100` emails/month), authentication emails such as verification links and password resets send automatically from ExaSpark's pre-authenticated default sender.

Upgrading to **Starter** (`1` custom domain, `1,000` emails/month) or **Pro** (up to `3` custom domains, `10,000` emails/month) puts your own brand directly in the **From** header and protects deliverability as volume scales.

## Choosing a sending subdomain vs your root domain

Decide which hostname your app will send from before copying DNS records. For almost every production business, a dedicated subdomain like `mail.yourdomain.com` beats sending automated app mail directly from your root domain.

| Factor | Dedicated subdomain (`mail.yourdomain.com`) | Root domain (`yourdomain.com`) |
| --- | --- | --- |
| **Reputation** | Protects everyday team email if automated bounces spike | Bounce spikes can hurt everyday team email delivery |
| **SPF safety** | Owns a clean, standalone `v=spf1` record | Risks colliding with Google Workspace or Microsoft 365 SPF |
| **Brand trust** | Displays your domain clearly (`bookings@mail.studionorth.co`) | Shortest address (`bookings@studionorth.co`) |
| **DMARC** | Passes relaxed alignment with `_dmarc.yourdomain.com` | Passes both strict and relaxed alignment |

Set `Reply-To: hello@yourdomain.com` on outgoing emails from `bookings@mail.studionorth.co` so customer replies still reach your main support inbox.

## Anatomy of SPF, DKIM, and DMARC records

Think of email authentication as a three-lock check. Each DNS record answers a different trust question before your message reaches the inbox.

### SPF: authorizing outbound servers

**SPF** (Sender Policy Framework) is a `TXT` record listing the exact mail servers permitted to send on behalf of your hostname. Receiving servers check the envelope sender domain against that list.

Two strict DNS rules trip up production setups:

- **One SPF record per hostname.** Publishing two `v=spf1` TXT records on the same hostname triggers a permanent `PermError` and fails both immediately.
- **Maximum 10 DNS lookups.** Every `include:`, `a`, `mx`, or `redirect` counts toward a hard RFC ceiling of 10 lookups; exceeding it breaks SPF everywhere.

### DKIM: cryptographic message signing

**DKIM** (DomainKeys Identified Mail) attaches an encrypted header signature using a private key managed on the sending mail server. You publish matching public keys in DNS under `<selector>._domainkey.<your-sending-host>` (typically two `CNAME` records enabling smooth key rotation).

Receiving servers fetch your public DKIM key from DNS to confirm the message was never altered in transit. Unlike SPF, DKIM signatures survive email forwarding intact.

### DMARC: alignment and enforcement policy

**DMARC** (Domain-based Message Authentication, Reporting & Conformance) sits at `_dmarc.yourdomain.com`. It verifies **alignment** between the visible `From:` domain and SPF or DKIM, and tells inbox providers how to handle failures.

```dns
; Example 1: Recommended dedicated sending subdomain (mail.studionorth.co)
; Copy the exact selectors and targets displayed in Cloud -> Email.

mail.studionorth.co.                TXT    "v=spf1 include:_spf.mail-provider.example ~all"
s1._domainkey.mail.studionorth.co.  CNAME  s1.domainkey.mail-provider.example.
s2._domainkey.mail.studionorth.co.  CNAME  s2.domainkey.mail-provider.example.
_dmarc.studionorth.co.              TXT    "v=DMARC1; p=none; rua=mailto:dmarc@studionorth.co; adkim=r; aspf=r; pct=100"
```

If you send directly from a root domain running Google Workspace or Microsoft 365, merge all authorized `include:` entries into a single `v=spf1` record:

```dns
; Example 2: One combined SPF record on a root domain (never two v=spf1 records)
studionorth.co.  TXT  "v=spf1 include:_spf.google.com include:_spf.mail-provider.example ~all"
```

## Step-by-step DNS setup and verification

1. **Add your domain in Cloud → Email** — Open **Cloud → Email**, click **Add sending domain**, and enter your subdomain (such as `mail.yourdomain.com`).
2. **Watch how your registrar formats Host fields** — Cloudflare, Namecheap, and GoDaddy usually auto-append `.yourdomain.com`. Enter `s1._domainkey.mail` instead of duplicating the root domain twice.
3. **Disable HTTP proxying on email records** — On Cloudflare, set every DKIM `CNAME` to **DNS only (grey cloud)**. Orange-cloud proxying breaks DKIM lookups immediately.
4. **Publish a starting DMARC record** — If `_dmarc.yourdomain.com` does not exist yet, publish `v=DMARC1; p=none; rua=mailto:dmarc@yourdomain.com`.
5. **Verify status and send live tests** — Wait 5–30 minutes for DNS propagation, click **Verify**, and send test emails to both Gmail and Outlook.

> **Note:** **Preview stays isolated.** Verify your sending domain for production delivery, and keep Preview tests pointed at your own inboxes. See [Preview vs Live isolation](https://exaspark.ai/docs/preview-vs-live/).

## Inspecting live headers and tightening DMARC safely

Open your test email in Gmail, select **Show original**, and confirm `spf=pass`, `dkim=pass`, and `dmarc=pass` appear inside `Authentication-Results`:

```http
Authentication-Results: mx.google.com;
       dkim=pass header.i=@mail.studionorth.co header.s=s1 header.b=a8F3cK1p;
       spf=pass (google.com: domain of bounces@mail.studionorth.co designates 203.0.113.42 as permitted sender);
       dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=mail.studionorth.co
```

Once every legitimate sender on your domain passes consistently, tighten DMARC across three stages so you never accidentally block real mail.

| Stage | Policy | Duration | Behavior |
| --- | --- | --- | --- |
| **1. Monitor** | `p=none; pct=100` | 2–4 weeks | Delivers mail normally while sending XML reports to your `rua` mailbox |
| **2. Quarantine** | `p=quarantine; pct=25` then `100` | 2–4 weeks | Routes unauthenticated or spoofed mail to recipient Spam |
| **3. Enforce** | `p=reject; pct=100` | Ongoing | Rejects forged messages before inbox delivery |

> **Example prompt (App):** Configure all production transactional emails to send from `Studio North <bookings@mail.studionorth.co>` with `Reply-To: hello@studionorth.co`. Include clean HTML and plain-text versions for sign-up links, booking receipts, and reminders, linking directly to `https://studionorth.co` without URL shorteners.

## Troubleshooting common DNS authentication errors

| Symptom | Most likely root cause | Reliable fix |
| --- | --- | --- |
| **Pending after 1 hour** | Host duplicated root domain (`mail.brand.com.brand.com`) | Enter only the subdomain prefix in your DNS Host column and re-verify |
| **DKIM fails in Gmail** | Cloudflare orange proxy enabled on DKIM `CNAME` | Switch every DKIM `CNAME` to **DNS only (grey cloud)** |
| **SPF shows `PermError`** | Two `v=spf1` TXT records on one host, or >10 lookups | Merge into one `v=spf1` record, or isolate app mail on `mail.yourdomain.com` |
| **DMARC fails alignment** | Visible `From:` domain differs from DKIM `d=` domain | Match your app's `From:` domain to the exact verified domain in **Cloud → Email** |
| **Outlook marks mail Junk** | New domain with image-only HTML or URL shorteners | Ramp gradually, include crisp plain text, and use direct domain links |
| **Custom sender blocked** | Free plan (`100/mo`) sends auth mail only via default sender | Upgrade to **Starter** (`1,000/mo`) or **Pro** (`10,000/mo`) |

## Next steps

- [Branded email & delivery](https://exaspark.ai/docs/branded-email/) — Review plan email limits, delivery log statuses, and bounce handling.
- [Transactional email flows](https://exaspark.ai/docs/transactional-email-flows/) — Wire welcome emails, receipts, and reminders with idempotent triggers.
- [Cloudflare, GoDaddy & Namecheap](https://exaspark.ai/docs/dns-cloudflare-godaddy/) — Registrar-specific DNS entry screenshots and propagation tips.

## From the blog

- [What is a domain name?](https://exaspark.ai/blog/what-is-a-domain-name/) — Plain-English guide to DNS records, subdomains, and routing.
- [How sign-in works](https://exaspark.ai/blog/how-sign-in-works/) — See why authenticated verification links and resets keep accounts safe.
- [App launch checklist](https://exaspark.ai/blog/app-launch-checklist/) — Verify custom domains, email DNS, and payments before opening traffic.
