# 01-Apr-2026 — Add MX record management for subdomain email routing [#207](https://github.com/nbarrett/ngx-ramblers/issues/207)

## [build 573](https://github.com/nbarrett/ngx-ramblers/actions/runs/23868774282) — [commit 4549a14](https://github.com/nbarrett/ngx-ramblers/commit/4549a142dff928cd8522e2e6c8d7966cd50d81bb)

_____

### MX Record Status on Mail Settings Page
The **Senders** tab on the Mail Settings page (`/admin/mail-settings?tab=senders`)
now includes an **MX Records** section that shows:
- Whether the required Cloudflare MX records are configured for your environment's domain
- A status table listing each required mail server with a check or cross indicator
- An **Add Missing MX Records** button that appears when records are missing,
allowing you to fix the configuration with a single click
This makes it easy for site administrators to diagnose and resolve email delivery
issues without needing direct access to Cloudflare.
### Automatic MX Records for New Environments
When a new environment is provisioned via the environment setup workflow, the
required MX records are now created automatically alongside the existing A and
AAAA DNS records. This prevents the email routing gap that previously affected
all new subdomain deployments.
### Background
Emails sent to `*.ngx-ramblers.org.uk` subdomain addresses were bouncing with
error `5.4.0 (network or routing status)` because no MX records existed to tell
sending mail servers where to deliver email. The root domain and all custom
domains (e.g. `ekwg.co.uk`) had correct MX records, but subdomains like
`kent.ngx-ramblers.org.uk` were missing them entirely.
The three required MX records point to Cloudflare's email routing servers:
- `route1.mx.cloudflare.net` (priority 16)
- `route2.mx.cloudflare.net` (priority 99)
- `route3.mx.cloudflare.net` (priority 2)
---
### Before Fix

![](https://ngx-ramblers.org.uk/api/aws/s3/site-content/cf98f92a-231f-46ab-8d7f-a66041380c88.jpeg)

---
### After Fix

![](https://ngx-ramblers.org.uk/api/aws/s3/site-content/433b4657-9bc3-4f25-8dac-0c3c3403f8ae.jpeg)

---
## Technical Details
### Server-side changes
- **`server/lib/cloudflare/cloudflare.model.ts`** — Added `priority` field to
`DnsRecord` and `DnsRecordResult` interfaces. Added `MxRecordDetail` and
`MxRecordStatus` interfaces for the status API response.
- **`server/lib/cloudflare/cloudflare-dns.ts`** — Updated `createDnsRecord()` to
conditionally include `priority` in the Cloudflare API POST body when present
(required for MX record creation).
- **`server/lib/cloudflare/cloudflare-email-routing-routes.ts`** — Added two new
authenticated API endpoints:
- `GET /api/cloudflare/email-routing/mx-records` — returns MX record status
for the current environment's subdomain
- `POST /api/cloudflare/email-routing/mx-records` — creates any missing MX
records and returns updated status
- **`server/lib/cli/commands/subdomain.ts`** — Updated
`setupSubdomainForEnvironment()` to create MX records after A/AAAA records,
with duplicate detection matching the existing pattern.
### Client-side changes
- **`projects/ngx-ramblers/src/app/models/cloudflare-email-routing.model.ts`** —
Added `MxRecordStatus`, `MxRecordDetail`, and `MxExistingRecord` interfaces.
- **`projects/ngx-ramblers/src/app/services/cloudflare/cloudflare-email-routing.service.ts`** —
Added `queryMxRecordStatus()` and `createMissingMxRecords()` service methods.
- **`projects/ngx-ramblers/src/app/pages/admin/system-settings/mail/mail-senders-list.ts`** —
Added MX record status section to the template with status badge, record table,
error display, and create button. Added `loadMxRecordStatus()` and
`createMissingMxRecords()` component methods.

### **lint**: replace native confirm() with inline UI and fix ESLint dialog rules

Replace native confirm() in committee settings with inline Confirm/Cancel
buttons. Refine ESLint confirm() selector to match only Literal and
TemplateLiteral arguments. Move nativeBrowserDialogRestrictions to
frontend-only config block. Exclude CLI files that legitimately use
@inquirer/prompts confirm() from dialog restrictions.