GoAdmio

mx

Add an MX record (mail server and optional priority) to a domain's DNS zone on Cloudflare

On this page: Overview · Quick start · Syntax · Arguments · Output · Examples · Troubleshooting · Details · See also


Overview

/go/mx is a short shortcut for adding an MX (mail exchanger) record to a domain's DNS zone on Cloudflare. MX records tell other mail servers where to deliver email for the domain.

It does not talk to Cloudflare itself. It passes your arguments to cloudflare, which makes the change through the Cloudflare API.


Quick start

# Send the domain's mail to mail.example.com
/go/mx example.com mail.example.com

Syntax

/go/mx <domain> <mail-server> [priority]

The values are positional, not --option pairs, and must be given in this order.


Arguments

Position Name Required Notes
1 <domain> Yes The domain whose DNS zone receives the record. It must already be on Cloudflare.
2 <mail-server> Yes The hostname of the mail server, such as mail.example.com. Use a hostname, not an IP address.
3 [priority] No MX priority. A lower number is tried first. If omitted, the default is chosen by cloudflare.

The command does not check its arguments. If an argument is missing or contains a space, it is passed on as is, and cloudflare may fail or misread the values.


Output

/go/mx prints nothing of its own. The messages you see, and the exit code, come from cloudflare. Every call is also appended to /var/log/go/mx.log.


Examples

# One mail server, default priority
/go/mx example.com mail.example.com
# Primary mail server with priority 10
/go/mx example.com mail.example.com 10
# Add a backup mail server with a higher number, so it is tried second
/go/mx example.com mail2.example.com 20
# Check the result
dig MX example.com +short
/go/checkmx

Troubleshooting

Symptom Likely cause Fix
The command fails with an error from cloudflare The domain is not on Cloudflare, or the Cloudflare API credentials are missing. Add the domain with dns and check the Cloudflare settings.
The record was created with the wrong server or priority The arguments were in the wrong order. Use the order <domain> <mail-server> [priority].
Mail is not delivered after the change DNS has not propagated yet, or the mail server value is wrong. Wait, then check with dig MX <domain> and checkmx.
Mail still goes to the old server An older MX record is still present. Check the zone on Cloudflare for other MX records. See Existing records.
Nothing happens, or the arguments are misread A required argument is missing. Pass both the domain and the mail server.

Details

What it runs

Depending on whether a priority is given, the command runs one of these:

# Without a priority
/go/cloudflare --domain <domain> --type mx --value <mail-server>

# With a priority
/go/cloudflare --domain <domain> --type mx --value <mail-server> --priority <priority>

Use cloudflare directly if you need its other options.

Existing records

This page does not say whether a new MX record replaces the domain's existing MX records or is added next to them. That is decided by cloudflare. Check the domain's records after the change, especially when moving mail to a new server.

An MX record covers delivery only. For mail to be accepted and trusted, the domain usually also needs SPF, DKIM, and DMARC records. See spf, dkim, and dmarc. For hosted mail providers, google and zoho set up the records for you.


See also

Command Description
cloudflare Configure Cloudflare DNS records, SSL, caching, and security settings for one or all hosted domains
checkmx Check every hosted domain for a missing MX record or an unexpected MX priority
txt Add a TXT record to a domain through Cloudflare
cname Add a CNAME record to a domain's DNS zone on Cloudflare
spf Add or refresh the SPF TXT record via Cloudflare
dkim Add a DKIM TXT record to a domain's Cloudflare DNS
dmarc Add a DMARC TXT record to a domain's Cloudflare DNS
google Add Google verification and Google Workspace DNS records to a domain through Cloudflare
zoho Configure Zoho mail integration (MX, SPF, DKIM)
dns Add one or all hosted domains to Cloudflare and set up their DNS zone