# MX record

An MX (mail exchanger) record says which servers receive email for a domain. When someone sends a message to you@example.com, their mail server looks up example.com's MX records and delivers to the server with the lowest priority number, trying the others if it can't get through.

- Record type: MX
- Type number: 15
- Used for: Email
- How common: Everyday
- Defined in: RFC 1035, RFC 5321, RFC 7505

## Format

```
<name> <ttl> IN MX <priority> <mail server>
```

| Field | What it means | Accepted values |
| --- | --- | --- |
| Name | The domain that receives the email: `@` for addresses like you@example.com. | A host name. |
| TTL | How long senders may cache the answer. | Seconds; 3600 is typical. |
| Priority | Order of preference. Lower numbers are tried first; equal numbers share the load. | 0 to 65535. Only the order between your records matters: 1 and 5 behave the same as 10 and 50. |
| Mail server | The host that accepts the mail. | A host name with its own A or AAAA record. Not an IP address, not a CNAME. `.` with priority 0 means the domain takes no email. |

## Examples

### Google Workspace

```
@ 3600 IN MX 1 smtp.google.com.
```

Google's current setup is a single MX. Older setups list five aspmx servers with priorities 1, 5, 5, 10, 10; both work.

### Microsoft 365

```
@ 3600 IN MX 0 example-com.mail.protection.outlook.com.
```

The host name is your domain with dots replaced by hyphens; copy it from the Microsoft 365 admin centre.

### Primary and backup

```
@ 3600 IN MX 10 mx1.example.net.
@ 3600 IN MX 20 mx2.example.net.
```

Senders try mx1 first and fall back to mx2.

### A domain that never receives email

```
@ 3600 IN MX 0 .
```

A null MX. Senders bounce mail straight away instead of retrying for days. Pair it with an SPF of v=spf1 -all and a DMARC p=reject.

## How mail finds your server

The sending server asks DNS for the MX records of the part after the @. It sorts them by priority, looks up the A or AAAA record of the first host, and connects to it on port 25. If that fails, it tries the next. If a domain has no MX records at all, senders fall back to its A record, which is rarely what anyone wants.

MX records only control receiving. Which servers may send as your domain is set by [SPF](https://lemon.domains/dns-records/spf), [DKIM](https://lemon.domains/dns-records/dkim) and [DMARC](https://lemon.domains/dns-records/dmarc).

## Changing email providers

- Lower the MX TTL to 300 a day before.
- Add the new provider's MX records and remove the old ones at the same time; mixing providers splits your mail.
- Update SPF to include the new provider and set up its DKIM key.
- Keep the old mailboxes open for a few days to catch mail from senders with cached records.

## TTL

3600 is the usual choice. Lower it to 300 before switching providers.

## Common mistakes

- Pointing an MX at an IP address. It must be a host name.
- Pointing an MX at a name that is a CNAME. The standard forbids it and some senders refuse to deliver.
- Leaving the old provider's MX records next to the new ones, so some mail lands in the old mailbox.
- Adding MX records on a subdomain (mail.example.com) when you meant the domain itself (@).
- Treating priority as a percentage. It's an order: the lowest number gets all the mail while it's up.

## At your DNS host

- Most dashboards have a separate Priority field; put only the host name in the value.
- Route 53 puts both in one value: 10 mail.example.com.
- Namecheap: under Advanced DNS, set Mail Settings to Custom MX to add your own.
- Cloudflare: MX records are never proxied, and the mail server's own A record must be DNS only (grey cloud).

## Questions

### What does MX stand for?

Mail exchanger: the server that exchanges (accepts) mail for the domain.

### Do lower or higher MX priorities win?

Lower. A priority 1 server is tried before a priority 10 server. Servers with the same number share the mail.

### Can I have email without an MX record?

Senders fall back to the domain's A record, but almost no web server accepts mail, so in practice no. Every domain that receives email needs MX records.

### Does the MX record affect sending email?

No. MX only controls where mail to your domain is delivered. Sending is covered by SPF, DKIM and DMARC.

## Related

- [SPF record](https://lemon.domains/dns-records/spf.md)
- [DKIM record](https://lemon.domains/dns-records/dkim.md)
- [DMARC record](https://lemon.domains/dns-records/dmarc.md)
- [TXT record](https://lemon.domains/dns-records/txt.md)
- [MTA-STS record](https://lemon.domains/dns-records/mta-sts.md)
- [A record](https://lemon.domains/dns-records/a.md)

Interactive version with a record checker and live lookup: https://lemon.domains/dns-records/mx
