Hasan's Journal

Stories, lessons, and scars from production.

Mehedi Hasan
Back to blog

Setting Up a Production-Grade Custom Domain Email System with Netlify, ImprovMX, and Brevo

Setting up professional custom domain email addresses (like contact@yourdomain.com) often pushes developers toward paid Google Workspace or Microsoft 365 plans. However, for personal portfolios, side projects, or early-stage applications, you can achieve enterprise-grade deliverability (9.5+/10) completely free using Netlify DNS, ImprovMX, and Brevo SMTP.

#DNS#WebDev#DevOps#Architecture

Architecture Overview

The system consists of four major components:

1. DNS & Routing: Netlify DNS

2. Inbound Mail: ImprovMX (Forwards incoming custom domain mail to your primary inbox)

3. Outbound Mail: Brevo Free SMTP (Relays outgoing mail sent via Gmail's 'Send mail as')

4. Authentication: SPF, DKIM, and single-record DMARC alignment

Inbound Route Configuration (ImprovMX)

To route emails sent to contact@yourdomain.com directly into your main personal inbox without running an independent mail server, configure ImprovMX MX records in your Netlify DNS:

1. MX Record 1: mx1.improvmx.com (Priority 10)

2. MX Record 2: mx2.improvmx.com (Priority 20)

Once these are set, ImprovMX seamlessly forwards all incoming messages to your designated personal address.

Fixing DMARC Multi-Record Conflicts

A common error encountered during email setup is the "Multiple DMARC records detected" warning. E-mail validation specifications strictly dictate that a domain must have exactly one DMARC record. Having multiple TXT records invalidates DMARC entirely across receiving mail servers.

The Problem

If you use multiple transactional services (e.g., Brevo, Postmark, Buttondown), you might end up with separate _dmarc entries:

# ❌ INVALID: Multiple DMARC TXT records _dmarc.yourdomain.com TXT "v=DMARC1; p=none; rua=mailto:you@yourdomain.com;" _dmarc.yourdomain.com TXT "v=DMARC1; p=none; rua=mailto:rua@dmarc.brevo.com;"

The Solution

Delete all existing _dmarc TXT entries in Netlify DNS and merge the reporting URIs into one combined TXT record using comma-separated rua= targets:

1. Name/Host: _dmarc

2. Type: TXT

3. TTL: 3600

Value: v=DMARC1; p=none; rua=mailto:you@yourdomain.com,mailto:rua@dmarc.brevo.com;

Outbound Relay Configuration (Gmail + Brevo)

To send email from contact@yourdomain.com directly from Gmail:

1. Generate a dedicated SMTP Key inside Brevo Dashboard > SMTP & API.

2. Open Gmail > Settings > Accounts and Import > Send mail as.

3. Input the following relay parameters:

i. SMTP Server: smtp-relay.brevo.com

ii. Port: 587 (TLS)

iii. Username: Your Brevo login email or assigned SMTP user ID

iv. Password: Your Brevo SMTP Key

Troubleshooting Common Auth Errors

1. 525 5.7.1 Unauthorized IP address: Occurs if IP access restrictions are active in Brevo. Disable IP restriction settings inside Brevo's API panel to allow dynamic Google server IPs to authenticate.

2. Authentication Failures: Ensure you are passing the generated SMTP key rather than your Brevo dashboard password.

Verification & Limits

Once fully linked, evaluate your setup using testing tools like Mail-Tester:

1. Deliverability Score: Expect 9.5/10 to 10/10 with fully aligned SPF, DKIM, and DMARC signatures.

2. Account Forwarding Limits: Avoid setting up forwarded aliases as "Alternate Emails" for Google Account logins. Forwarding providers like ImprovMX can occasionally run into soft-bounce rate limits (4.7.28 Unsolicited Mail) from Google when relaying system verification tokens back to the same destination. Use your native account address for authentication, and reserve custom domain relays strictly for communication.