How to Disable Local Mail Delivery in Sendmail: Forcing External MX Lookup


2 views

When Sendmail encounters email addresses for domains that resolve to the local machine (even indirectly), it defaults to local delivery rather than following MX records. This behavior persists even when:

  • The domain isn't in local-host-names
  • MX records explicitly point elsewhere
  • You only want outbound SMTP functionality

Run Sendmail's address test mode to see how it handles your domain:

sendmail -bt
> 3,0 info@example.com

If you see $# local $: info in the output, Sendmail is configured for local delivery.

The most reliable approach is to rebuild Sendmail's configuration with proper mailer settings:

# Edit your sendmail.mc file
dnl Disable local mail delivery for specific domains
FEATURE(blacklist_recipients')dnl
LOCAL_DOMAIN(example.com')REJECT
LOCAL_DOMAIN(example.com')ERROR:5.7.1:Mail not accepted for local delivery

# Rebuild the configuration
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
service sendmail restart

For temporary solutions or testing, modify the access database:

# Add to /etc/mail/access
Connect:example.com         RELAY
To:example.com              RELAY

# Rebuild access.db
makemap hash /etc/mail/access.db < /etc/mail/access
service sendmail restart

After making changes, test again with:

sendmail -bt
> 3,0 info@example.com

The output should now show SMTP routing instead of local delivery.

  • Ensure your server isn't listed as MX for the domain
  • Check DNS resolution doesn't point to localhost
  • Review all class {w} and class {P} definitions

For stubborn domains that still route locally, examine full ruleset processing:

sendmail -bt -d21.12
> /tryflags es
> /try smtp info@example.com

This shows the complete ruleset evaluation chain.


When configuring Sendmail as an outgoing SMTP server for web applications, you might encounter situations where emails addressed to your domain (e.g., @example.com) get delivered locally instead of following MX records. This typically happens when Sendmail considers your domain as part of its local delivery configuration.

First, verify if your domain is being treated as local by Sendmail. Run this diagnostic command:

sendmail -bt
3,0 info@example.com

If you see output ending with $# local $: info, it confirms Sendmail is handling the domain locally.

Edit your /etc/mail/sendmail.mc file and add these critical modifications:

dnl Disable local delivery for specific domains
FEATURE(virtusertable', hash -o /etc/mail/virtusertable.db')dnl
FEATURE(genericstable', hash -o /etc/mail/genericstable.db')dnl
FEATURE(always_add_domain')dnl
define(confDELIVERY_MODE', deferred')dnl

Create or modify /etc/mail/local-host-names to ensure your domain isn't listed:

# Remove or comment out your domain if present
# example.com
localhost
localhost.localdomain

Create a mailertable entry to force external delivery:

# /etc/mail/mailertable
example.com   esmtp:[mail.example.com]

Then compile the changes:

makemap hash /etc/mail/mailertable < /etc/mail/mailertable
make -C /etc/mail
systemctl restart sendmail

Verify the changes with this command sequence:

sendmail -bv info@example.com
sendmail -d60.5 -bv info@example.com

If you prefer all mail to route through your mail server:

define(SMART_HOST', [mail.example.com]')dnl
define(RELAY_MAILER',esmtp')dnl
define(RELAY_MAILER_ARGS', TCP $h 587')dnl

If emails still deliver locally:

  1. Check for cached DNS entries with dig MX example.com
  2. Verify Sendmail isn't falling back to local delivery with sendmail -d8.20 -bv test@example.com
  3. Ensure no conflicting entries in /etc/mail/access