# Setting up email delivery with Mailtrap

You create an API token at Mailtrap, store it under Connections, and then monitor status and sending domains directly in MainPath.

> Source: https://www.mainpath.ai/en/docs/smtp-mailtrap-setup/

Mailtrap is integrated into MainPath as its own connection type. You store only an API token; MainPath handles sending through the Sending API, the status display, and the monitoring of your sending domains.

```mermaid
flowchart LR
  cred["Organization's Mailtrap connection"]
  svc["Your project's backend"]
  api["Mailtrap Sending API"]
  mx["Recipient's mail server"]
  svc -->|"reads credentials"| cred
  svc -->|"API token"| api
  api --> mx
```

For a different provider, create a generic **Email (SMTP)** connection instead; [Email delivery]({{< relref "email-delivery" >}}) describes the differences.

## Preparing at Mailtrap

1. Create an account at [mailtrap.io](https://mailtrap.io/) or sign in.
2. Under **Sending Domains**, enter your sender domain and set the displayed DNS records for SPF, DKIM, and DMARC at your domain provider; sending is only enabled after verification. You can also take care of this step later from within MainPath.
3. Under **Settings → API Tokens**, create a Sending API token and copy it.

## Creating the connection in MainPath

1. Open **Connections** in the sidebar and click **Add connection**.
2. Choose the **Mailtrap** tile.
3. Enter the **API token**, optionally with a **sender name** and a **sender address** from your verified sending domain.
4. Save. The connection is then available in projects under **Mail account**.

## Monitoring status and domains in MainPath

The Mailtrap connection's tile opens its detail view with the **status** of the connection, the plan and sending volume of your Mailtrap account, your sending domains with their verification status, and for each domain the DNS records with type, name, value, and check status. With **Add domain** you create new sending domains right here.

## Selecting the mail account in the project

When editing the project, select the Mailtrap connection under **Mail account** in the backend's settings. Mailtrap, Resend, SendGrid, and SMTP connections are listed there together.

## If something does not work

If the **status** shows an error, check the API token and create a new one at Mailtrap if necessary. If Mailtrap rejects sending or mail does not arrive, the sending domain is usually not verified yet; compare the DNS records in the detail view with those at your domain provider. If a domain is missing from the list, create it with **Add domain** and set the displayed records.

## See also

- [Connections]({{< relref "connections" >}})
- [Email delivery]({{< relref "email-delivery" >}})
- [SMTP with Resend]({{< relref "smtp-resend-setup" >}})
- [SMTP with SendGrid]({{< relref "smtp-sendgrid-setup" >}})

