> ## Documentation Index
> Fetch the complete documentation index at: https://docs.emailr.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Custom Receiving Domains

> Receive emails using your own domain.

Besides [using Emailr-managed domains](/docs/guides/dashboard/receiving/introduction), you can also receive emails using your own custom domain, such as `yourdomain.tld`.

Here's how to receive emails using a *new* custom domain.

## 1. Add the DNS record

First, [verify your domain](/docs/guides/dashboard/domains/introduction).

Receiving emails requires an extra [MX record](https://emailr.dev/guides/knowledge-base/how-do-i-avoid-conflicting-with-my-mx-records) to work. You'll need to add this record to your DNS provider.

1. Go to the [Domains](https://app.emailr.dev/dashboard/domains) page
2. Copy the MX record
3. Paste the MX record into your domain's DNS service

<img alt="Screenshot placeholder" src="https://mintcdn.com/emailrdev/tSm2WeCvU8-lHmTx/images/placeholder.svg?fit=max&auto=format&n=tSm2WeCvU8-lHmTx&q=85&s=93891ced94bad8f8c38f90b5be99f73c" width="800" height="450" data-path="images/placeholder.svg" />

<Info>
  If you already have existing MX records for your domain (because you're already
  using it for a real inbox, for example), we recommend that you
  create a subdomain (e.g. `subdomain.yourdomain.tld`) and add the MX record
  there. This way, you can use Emailr for receiving emails without affecting
  your existing email service. Note that you will *not* receive emails at Emailr
  if the required `MX` record is not the lowest priority value for the domain.

  Alternatively, configure your existing email service to forward messages to an
  address configured in Emailr.
</Info>

## 2. Configure webhooks

Next, create a new webhook endpoint to receive email events.

1. Go to the [Webhooks](https://app.emailr.dev/dashboard/webhooks) page
2. Click "Add Webhook"
3. Enter the URL of your webhook endpoint
4. Select the event type `email.received`
5. Click "Add"

<img alt="Screenshot placeholder" src="https://mintcdn.com/emailrdev/tSm2WeCvU8-lHmTx/images/placeholder.svg?fit=max&auto=format&n=tSm2WeCvU8-lHmTx&q=85&s=93891ced94bad8f8c38f90b5be99f73c" width="800" height="450" data-path="images/placeholder.svg" />

## 3. Receive email events

In your application, create a new route that can accept `POST` requests.

For example, here's how you can add an API route in a Next.js application:

```js app/api/events/route.ts theme={null} theme={null}
import type { NextRequest } from 'next/server';
import { NextResponse } from 'next/server';

export const POST = async (request: NextRequest) => {
  const event = await request.json();

  if (event.type === 'email.received') {
    return NextResponse.json(event);
  }

  return NextResponse.json({});
};
```

Once you receive the email event, you can process the email body and attachments. We also recommend implementing [webhook request verification](/docs/guides/dashboard/webhooks/verify-webhooks-requests) to secure your webhook endpoint.

```json theme={null} theme={null}
{
  "type": "email.received",
  "created_at": "2024-02-22T23:41:12.126Z",
  "data": {
    "email_id": "56761188-7520-42d8-8898-ff6fc54ce618",
    "created_at": "2024-02-22T23:41:11.894719+00:00",
    "from": "Acme <onboarding@emailr.dev>",
    "to": ["delivered@emailr.dev"],
    "bcc": [],
    "cc": [],
    "message_id": "<example+123>",
    "subject": "Sending this example",
    "attachments": [
      {
        "id": "2a0c9ce0-3112-4728-976e-47ddcd16a318",
        "filename": "avatar.png",
        "content_type": "image/png",
        "content_disposition": "inline",
        "content_id": "img001"
      }
    ]
  }
}
```

## Enabling receiving for an existing domain

If you already have a verified domain, you can enable receiving by using the toggle in the receiving section of the domain details page.

<img alt="Screenshot placeholder" src="https://mintcdn.com/emailrdev/tSm2WeCvU8-lHmTx/images/placeholder.svg?fit=max&auto=format&n=tSm2WeCvU8-lHmTx&q=85&s=93891ced94bad8f8c38f90b5be99f73c" width="800" height="450" data-path="images/placeholder.svg" />

After enabling receiving, you'll see a modal showing the MX record that you need to add to your DNS provider to start receiving emails.

Once you add the MX record, confirm by clicking the "I've added the record" button and wait for the receiving record to show as "verified".

## FAQ

<AccordionGroup>
  <Accordion title="What happens if I already have MX records for my domain?">
    If you already have existing MX records for your domain, we recommend that you
    create a subdomain (e.g. `subdomain.yourdomain.tld`) and add the MX record
    there.

    That's because emails will usually only be delivered to the MX record with the lowest
    priority value. Therefore, if you add Emailr's MX record to your root domain alongside existing MX records,
    it will either not receive any emails at all (if the existing MX records have a lower priority),
    or it will interfere with your existing email service (if Emailr's MX record has a lower priority). If you
    use the same priority, email delivery will be unpredictable and may hit either Emailr or your existing email
    service.

    If you still want to use the same domain both in for Emailr and your day-to-day
    email service, you can also set up forwarding rules in your existing email service
    to forward emails to an address that's configured in Emailr.
  </Accordion>

  <Accordion title="I have already verified my domain for sending. Do I need to verify it again for receiving?">
    No, you do not need to verify your entire domain again. If you already have a
    verified domain for sending, you can simply enable receiving for that domain,
    add the required MX record to your DNS provider, and click "I've added the record"
    to start verifying *only* the MX record.
  </Accordion>
</AccordionGroup>
