# Set up SPF, DKIM and DMARC (/docs/guides/spf-dkim-dmarc)

Mailbox providers trust mail that proves it comes from the domain in its From address. Three DNS
records do that. This guide adds a domain to coss.com, publishes its records, verifies it and takes
its DMARC policy from monitoring to `p=reject`.

## What SPF, DKIM and DMARC do [#what-spf-dkim-and-dmarc-do]

- **SPF** lists the servers allowed to send mail for a domain. Receivers check it against the
  envelope sender (the bounce address, or Return-Path), not the From address people see.
- **DKIM** signs each message with a private key. Receivers fetch the public key from DNS
  (`<selector>._domainkey.<domain>`) and check that the message wasn't changed and that the signing
  domain vouches for it.
- **DMARC** ties both to the From address. A message passes when SPF or DKIM passes **and** its
  domain is aligned with the From domain. The DMARC record tells receivers what to do with mail
  that fails (`p=none`, `p=quarantine` or `p=reject`) and where to send reports about it.

## Add your domain [#add-your-domain]

Add the domain in the dashboard (**Domains**) or with the SDK. Domains belong to the organization
and are shared by all of its projects; live keys can only send from verified ones.

```ts twoslash
import { Coss } from "coss";
const coss = new Coss();
// ---cut---
const { data: domain, error } = await coss.domains.create({ name: "acme.com" });

for (const record of domain?.records ?? []) {
  console.log(record.purpose, record.type, record.name, record.value, record.required);
}
```

## The DNS records coss.com asks for [#the-dns-records-cosscom-asks-for]

| Purpose              | Type    | Name                             | Value                                                          |
| -------------------- | ------- | -------------------------------- | -------------------------------------------------------------- |
| DKIM (three records) | `CNAME` | `<token>._domainkey.example.com` | `<token>.dkim.amazonses.com`                                   |
| MAIL FROM            | `MX`    | `send.example.com`               | `feedback-smtp.<region>.amazonses.com` (priority 10)           |
| MAIL FROM SPF        | `TXT`   | `send.example.com`               | `v=spf1 include:amazonses.com ~all`                            |
| DMARC (recommended)  | `TXT`   | `_dmarc.example.com`             | `v=DMARC1; p=none; rua=mailto:dmarc-<token>@inbound.coss.com;` |

Copy the exact values from the dashboard or the `records` array: the DKIM tokens, the region and the
DMARC report address are specific to your domain.

- The three DKIM records sign your mail as your own domain, so DKIM is aligned for DMARC.
- SPF lives on the `send.` subdomain, the envelope sender coss.com uses for bounces. Your root
  domain's SPF record doesn't change, so it keeps working for your other mail.
- The DMARC record is optional for verification (`required: false`) but recommended. It starts in
  monitoring mode and sends aggregate reports to coss.com.

If you already have a DMARC record, keep it and add coss.com's address to its `rua` tag (addresses
are comma-separated) instead of publishing a second one.

## One-click setup with Domain Connect [#one-click-setup-with-domain-connect]

If your DNS provider supports [Domain Connect](https://www.domainconnect.org) (Cloudflare, for
example), the domain's page in the dashboard shows **Connect with** your provider. Your provider
lists the records coss.com would add and asks you to confirm; then coss.com checks them right away.
Only missing records are added, and a DMARC record only when your domain has none, so an existing
policy is never weakened.

## Verify the domain [#verify-the-domain]

coss.com checks the records automatically. Verification usually takes minutes, but DNS changes can
take longer to propagate; a domain not verified within 72 hours fails. To check now, use **Verify**
in the dashboard or `coss.domains.verify()`:

```ts twoslash
import { Coss } from "coss";
const coss = new Coss();
declare const domainId: string;
// ---cut---
const { data: domain } = await coss.domains.verify(domainId);

console.log(domain?.status, domain?.can_send); // "verified" true
for (const record of domain?.records ?? []) {
  if (record.status !== "verified") {
    console.log(record.purpose, record.name, record.status, record.found);
  }
}
```

Each record's `status` is `verified`, `missing`, `mismatch` or `not_checked`, and `found` shows what
DNS returned when it didn't match. Calling `verify` on a `failed` domain starts over with new DKIM
records, which you publish again.

## Move DMARC from p=none to p=reject [#move-dmarc-from-pnone-to-preject]

Mail providers send daily aggregate reports to the `rua` address. coss.com reads them, shows every
source that sent as your domain on the domain's **DMARC** tab, and unlocks each stricter step once
the last 14 days of reports say it's safe:

1. **Monitor** (`p=none`): nothing changes for delivery; reports start arriving.
2. **Quarantine** (`p=quarantine`): once mail through coss.com and all reported mail pass at high
   enough rates, and no other significant source fails.
3. **Reject** (`p=reject`): after 14 days of a full quarantine, with the same checks.

coss.com never changes your DNS. When a step is ready, the dashboard shows the record to publish and
owners and admins get an email with it. The same status is in the API:

```ts twoslash
import { Coss } from "coss";
const coss = new Coss();
declare const domainId: string;
// ---cut---
const { data: dmarc } = await coss.domains.dmarc.get(domainId);

console.log(dmarc?.stage); // "monitoring"
if (dmarc?.next && dmarc.ready) {
  console.log(`Publish at _dmarc: ${dmarc.next.record}`);
}
```

A source in the reports that isn't coss.com is another service sending as your domain (a CRM, a
help desk, your mail server) or someone spoofing it. Set up DKIM or SPF for your own services,
aligned with your domain, before you tighten the policy. [DMARC](/docs/email/dmarc) lists the exact
checks. To build or read a record by hand, use the free
[DMARC record generator and checker](/products/tools/dmarc-record-checker).

## Show your logo with BIMI [#show-your-logo-with-bimi]

Once DMARC is at `p=quarantine` or `p=reject` for all of your mail, you can publish a BIMI record so
Gmail, Apple Mail and others show your logo next to your emails. It needs an SVG logo and a mark
certificate (VMC or CMC). See [brand logos (BIMI)](/docs/email/bimi).

## Bulk sender requirements [#bulk-sender-requirements]

Gmail, Yahoo and Outlook require bulk senders to support one-click unsubscribe. coss.com adds the
headers for the categories you choose: see [one-click unsubscribe](/docs/email/unsubscribe).

## Common mistakes [#common-mistakes]

- **Two SPF records at one name.** A name may have only one `v=spf1` record; with two, SPF fails
  with an error. Merge them into one. coss.com's SPF is on `send.`, so it never adds a second
  record to your root domain.
- **The domain added twice.** Many DNS providers append your domain to the name you type, so
  `send.example.com` becomes `send.example.com.example.com`. Enter only `send` if yours does.
- **Proxied DKIM records.** At providers that can proxy records (Cloudflare), keep the DKIM
  `CNAME`s DNS-only, or they won't resolve to the keys.
- **Strict SPF alignment.** `aspf=s` requires the envelope sender to be exactly the From domain,
  so SPF on `send.example.com` no longer aligns. Keep the default relaxed alignment.
- **Two DMARC records.** Receivers may ignore both. Edit the one you have.
- **Going straight to `p=reject`.** Without reading reports first, you can block your own CRM or
  help desk. Follow the steps on the **DMARC** tab.

## Next steps [#next-steps]

- [Domains](/docs/email/domains): the reference for domains, verification and tracking domains.
- [DMARC](/docs/email/dmarc): reports, checks and the API.
- [Brand logos (BIMI)](/docs/email/bimi): the BIMI record and its checks.
- [Sending email](/docs/email/sending): send your first email from the verified domain.
