MX Record Configuration Guide: Routing Email Traffic Between Exchange and IMAP Servers for Split User Distribution


2 views

When migrating email services while maintaining legacy systems, administrators often need to split user traffic between different mail servers under the same domain. This presents unique MX record configuration challenges that standard setups don't address.

Traditional MX records typically point to a single mail server or use priority values for failover. Neither approach solves the requirement for active-active routing based on recipient addresses.

; Standard MX record example (won't work for split delivery)
example.com.  3600  IN  MX  10  mail1.example.com.
example.com.  3600  IN  MX  20  mail2.example.com.

We actually need two complementary approaches working together:

  1. Primary MX records pointing to a mail gateway
  2. Internal routing rules on the gateway server

Here's how to configure this in practice:

; DNS Configuration
example.com.     3600  IN  MX  10  gateway.example.com.

; Postfix example (gateway configuration)
transport_maps = hash:/etc/postfix/transport

# /etc/postfix/transport content:
john@example.com   smtp:[exchange-server]:25
sarah@example.com  smtp:[imap-server]:25

When integrating Exchange, you'll need to:

  • Configure Receive Connectors to accept mail from gateway
  • Set up proper authentication between systems
  • Handle calendar/meeting requests differently for mixed environments

Essential checks for stable operation:

# Verify MX records
dig MX example.com +short

# Test mail routing
swaks --to john@example.com --server gateway.example.com
swaks --to sarah@example.com --server gateway.example.com

For larger deployments, consider:

; DNS Configuration
example.com.       3600  IN  MX  10  exchange.example.com.
legacy.example.com. 3600  IN  MX  10  imap.example.com.

# Then configure email addresses as:
john@example.com
sarah@legacy.example.com

When migrating email services or maintaining hybrid environments, administrators often need to route emails differently for users on different platforms while maintaining a single domain. The fundamental question is whether MX records can handle this split delivery.

MX records alone cannot solve this problem because they operate at the domain level, not the user level. When an email arrives for yourdomain.com, the sending server will:

  1. Query MX records for yourdomain.com
  2. Deliver to the highest priority server
  3. Only try lower priority servers if delivery fails

Here are three practical approaches to achieve split delivery:

1. Smart Host Configuration

Configure your primary MX server (Exchange in this case) to relay specific users to the IMAP server:

# Exchange Transport Rule Example
New-TransportRule -Name "ForwardToIMAP" 
  -RecipientAddressContainsWords "user1@domain.com","user2@domain.com"
  -RedirectMessageTo "imapserver@domain.com"

2. Shared Database Approach

Implement a centralized user database that both systems query for routing:

// Pseudocode for routing decision
function routeEmail(email) {
  const userType = db.query(SELECT service_type FROM users WHERE email = ?, [email]);
  return userType === 'exchange' ? exchangeServer : imapServer;
}

3. Proxy Solution

Deploy an SMTP proxy that makes routing decisions:

# Sample Postfix configuration
transport_maps = hash:/etc/postfix/transport

# /etc/postfix/transport content
user1@domain.com   smtp:[imap.server.ip]
user2@domain.com   smtp:[exchange.server.ip]

While you can't split by user in MX records, here's how you might set up redundant MX records:

domain.com.   3600    IN    MX    10 mail1.domain.com.
domain.com.   3600    IN    MX    20 mail2.domain.com.
  • Ensure proper SPF records for all mail servers
  • Monitor both systems for bounces or delays
  • Implement consistent DKIM signing across both platforms
  • Consider using a cloud email gateway as the primary MX

Common issues and solutions:

# Testing email routing
telnet mail1.domain.com 25
EHLO example.com
MAIL FROM:<test@example.com>
RCPT TO:<targetuser@domain.com>