---
name: azion-receive-mail-with-mx-records
description: >-
  Add an MX record that names your mail servers and their priorities in Edge DNS, from Azion Console, the Azion CLI, or the API, and check the answer with dig.
---

# Receive mail with MX records

You can add an MX record to a zone in [Edge DNS](/en/documentation/platform/edge-dns/) from Azion Console, the Azion CLI, or the Azion API. The record below names two mail servers for `example.com`, each with a priority, so that mail sent to addresses at the domain reaches them. To add another type of record, refer to [Add, edit, or delete a record](/en/documentation/guides/application-security/dns/add-records/).

---

Choose the interface you work in. The prerequisites and the steps to add the record follow that choice.

## Prerequisites

- A zone for your domain in Edge DNS. To create one, refer to [Create, edit, or delete a zone](/en/documentation/guides/application-security/dns/edge-dns-configure-main-settings/).
- The hostname and the priority of each mail server, as your mail provider gives them.
- The **Edit Edge DNS** permission. Refer to [Teams permissions](/en/documentation/fundamentals/teams-permissions/).

**Console**

- Access to Azion Console. To sign in, refer to [Access Azion Console](/en/documentation/guides/platform/account-and-billing/how-to-access-azion-console/).

**CLI**

- The [Azion CLI](/en/documentation/devtools/cli/) installed and authorized, and the ID of the zone.

**API**

- A [personal token](/en/documentation/guides/platform/account-and-billing/personal-tokens/), `curl`, and the `id` of the zone.

---

## Add the MX record

One MX record holds every mail server for a name, one value per server, up to 10 values. Each value is a priority, a space, and the mail server's hostname. The record goes on `@`, the zone apex, to receive mail for addresses such as `user@example.com`. For the rules of the value, refer to [MX](/en/documentation/platform/edge-dns/record-types/#mx).

**Console**

To add the record in Azion Console:

1. **Open the Edge DNS page**

   Access [Azion Console](https://console.azion.com/) > **Edge DNS**.

2. **Open the zone's Records tab**

   On the **Zones** page, select the row of the zone, then select the **Records** tab.

3. **Select + Record**

   The **Create Record** drawer opens.

4. **Enter the record name**

   In **Name**, enter `@`. The Console adds the domain for you, so the record answers for `example.com`.

5. **Select the MX record type**

   In **Record Type**, select *MX - Mail exchange*.

6. **Keep the TTL**

   Keep **TTL (seconds)** at `3600`.

7. **Enter one mail server per line**

   In **Value**, enter `10 mail.example.com` on the first line and `20 mail2.example.com` on the second.

8. **Select Save**

The Console shows `Edge DNS Record has been created`, and the record appears in the **Records** table with both values.

**CLI**

To add the record with the Azion CLI, repeat `--rdata` once per mail server. Replace `<zone-id>` with the ID of your zone:

```bash
azion create dns-record --zone-id <zone-id> --name @ --type MX \
  --rdata "10 mail.example.com" --rdata "20 mail2.example.com" --ttl 3600
```

The command prints the ID of the record:

```text
Created DNS record with ID 100775
```

To read the record, list the records of the zone:

```bash
azion list dns-record --zone-id <zone-id>
```

The MX record shows both values in one row, separated by a comma:

```text
ID      NAME  TYPE  TTL   RDATA
…
100775  @     MX    3600  10 mail.example.com, 20 mail2.example.com
…
```

The zone holds one MX record on `@` with two mail servers.

**API**

To add the record with the Azion API, send a `POST` request to the zone's records endpoint. Replace `<zone-id>` with the `id` of your zone:

```bash
curl -X POST https://api.azion.com/v4/workspace/dns/zones/<zone-id>/records \
  -H "Authorization: Token [TOKEN VALUE]" \
  -H "Content-Type: application/json" \
  -d '{"name":"@","type":"MX","rdata":["10 mail.example.com","20 mail2.example.com"],"ttl":3600}'
```

A `201` returns the record, with one item in `rdata` per mail server:

```json
{
  "state": "executed",
  "data": {
    "id": 100178,
    "description": "",
    "name": "@",
    "ttl": 3600,
    "type": "MX",
    "rdata": ["10 mail.example.com", "20 mail2.example.com"],
    "policy": "simple",
    "weight": 255
  }
}
```

The zone holds one MX record on `@` with two mail servers.

A second MX record on the same name is refused with `19004` `Record Already Exists`. To add a mail server later, edit the existing record and add a value.

---

## Check the answer

Ask Azion's nameserver directly, without your resolver's cache, for the MX record of the domain. Replace `example.com` with your domain:

```bash
dig +short @ns1.aziondns.net example.com MX
```

The nameserver returns one line per value, with the priority first:

```text
10 mail.example.com.
20 mail2.example.com.
```

> **Caution**
>
> Query the name only after you save the record. A name queried before its record exists is answered `NXDOMAIN` for up to one hour, the SOA minimum.

If the command prints nothing, refer to [A new record returns NXDOMAIN](/en/documentation/platform/edge-dns/troubleshooting/#a-new-record-returns-nxdomain). A change to an existing MX record can take a few minutes to reach every nameserver. For the reasons, refer to [Caching and propagation](/en/documentation/platform/edge-dns/how-it-works/#caching-and-propagation).

---

## Next steps

- [Verify a domain with a TXT record](/en/documentation/guides/application-security/dns/txt-verification.md): Add the TXT value a service asks for on your domain.
- [Record types](/en/documentation/platform/edge-dns/record-types.md): The value format and rules of each record type.
- [Migrate nameservers to Azion](/en/documentation/guides/platform/migration/migrate-ns-to-azion.md): Delegate your domain to Edge DNS so mail servers find the record.
- [Query a zone with dig](/en/documentation/guides/application-security/dns/run-the-dig-command.md): Read the status and flags of an answer, and compare resolvers.
