---
title: "Set up a sending domain"
description: "Add a domain for a project's email to come from, create the DNS records Agentpost lists, and wait for the domain to verify."
url: "https://agentpost.tools/docs/platform/guides/sending-domain"
kind: guide
needs:
  - what: "The `api` helper that sends each request"
    from: "https://agentpost.tools/docs/platform/quickstart.md"
  - what: "Your credential, `token`, as an owner or admin of the workspace that holds the project"
    from: "https://agentpost.tools/docs/platform/guides/sign-up.md"
  - what: "A project, `project`"
    from: "https://agentpost.tools/docs/platform/guides/keys.md"
---

# Set up a sending domain

Set up a domain before the project emails real addresses, such as sign-in codes for your product’s customers; [Projects](/docs/platform/concepts/projects.md#email) explains what happens to email until it verifies. Adding a domain takes the role of an owner or an admin; [Roles](/docs/platform/concepts/workspaces.md#roles) lists each role’s permissions.

## Before you start

-   The `api` helper that sends each request, from [Platform quickstart](/docs/platform/quickstart.md).
-   Your credential, `token`, as an owner or admin of the workspace that holds the project, from [Start a workspace](/docs/platform/guides/sign-up.md).
-   A project, `project`, from [Create a project and issue a key](/docs/platform/guides/keys.md).

This page's code continues the script of the pages above: run its blocks after theirs, in the same file. To run them as a script of their own, first copy each helper from the page that defines it, and set each other value, such as a key or an ID, to one you already have.

## 1\. Add the domain

Send the domain to `PUT /v1/projects/{id}/sending-domain`. Replace `example.com` with a domain whose DNS records you can change.

```ts
const added = await api(
  'PUT',
  `/v1/projects/${project.id}/sending-domain`,
  token,
  { domain: 'example.com' },
);
const { records } = added.sendingDomain;
console.log(added.sendingDomain.status, added.sendingDomain.address); // pending no-reply@example.com
```

The default address is `no-reply@` the domain. To use another address, send `address` too, such as `{ domain: 'example.com', address: 'hello@example.com' }`. Use the same domain and 1 to 64 letters, digits, or `. _ % + -` before the `@`. Changing the address on an already verified domain needs no new verification.

Adding a domain may answer [`conflict`](/docs/errors.md#conflict) with `details.reason` set to `domain_in_use`, or [`invalid_request`](/docs/errors.md#invalid_request).

## 2\. Create the DNS records

Create every record in `records` at the domain’s DNS provider, with its `type`, `name`, and `value` exactly as given. Verification waits on all of them: three `CNAME` records that sign the email, and an `MX` and a `TXT` record for the subdomain bounces return to.

`added.sendingDomain.recommended` lists records that help delivery but that nothing waits on, such as a DMARC `TXT` record when the domain has none. Create them too.

While a new domain is pending, the project’s current sender keeps sending, so changing domains leaves no gap.

## Check it worked

Read the domain until it leaves `pending`. A read rechecks a pending domain if the last check was at least 10 seconds ago.

```ts
let state = await api(
  'GET',
  `/v1/projects/${project.id}/sending-domain`,
  token,
);
while (state.sendingDomain.status === 'pending') {
  await new Promise((resolve) => setTimeout(resolve, 5 * 60_000));
  state = await api('GET', `/v1/projects/${project.id}/sending-domain`, token);
}
console.log(state.sendingDomain.status, state.sender?.address); // verified no-reply@example.com
```

Check that `status` is `verified` and `sender.address` is the address you requested. If the domain verified and the sender hasn’t switched, read again. Agentpost also checks on its own, every 5 minutes for the first hour, then hourly. While the domain is pending, `waitingOn` lists what is still missing.

A domain that can’t verify, such as one still missing a record after 72 hours, becomes `failed`, and `failure` says why and what to do. Send the same `PUT` again to start over, and create the records it answers with, which may be new. Another workspace can add a failed domain if no project sends from it.

The [sending domain reference](/docs/platform/reference/sending-domain.md) has every field, and [Remove the sending domain](/docs/platform/reference/sending-domain.md#remove-the-sending-domain) stops sending from it.
