I am using Sendmail on a Centos server to send email for PHP scripts, but the problem is that mail is delivered to a local mailbox on the machine rather than what is specified in the MX records for the domain - which actually point to another machine I use for email.

I would like sendmail to not try and locally deliver mail for the domain the machine is setup for, is there a simple way to disable local delivery?

The domain is not in the local-host-names file.

I've already done lots of googling and I have looked at:

Sendmail Configuration to not deliver mail to local machine

Disable local delivery in Sendmail

But either there is no answer or it is not suitable.

I don't want to relay to another server, i just want it to send mail regardless of domain.

To provide an example:

I have two servers, one is the mail server at mail.example.com and a web server which is example.com, when I use the smtp service on the web server it currently routes mail to a local mailbox on example.com, but it should be going to mailboxes on mail.example.com

Output of sendmail -bt returns:

ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
> 3,0 [email protected]
canonify           input: info @ example . com
Canonify2          input: info 
Canonify2        returns: info 
canonify         returns: info 
parse              input: info 
Parse0             input: info 
Parse0           returns: info 
ParseLocal         input: info 
ParseLocal       returns: info 
Parse1             input: info 
Parse1           returns: $# local $: info
parse            returns: $# local $: info
  • stalkr.net/forum/… Seems to be the closest thing to what i'm actually after. Specifically the MAIL_HUB setting mentioned, but it does not seem to actually work.
    – user6091
    Sep 15, 2009 at 1:14
  • Try the following: sendmail -bt and then type 3,0 [email protected] It will give you a lot of rewrite rules, the last ones should give you the relay it will use. Please provide the output. Sep 15, 2009 at 5:06
  • Hi Francois, i've edited my question to include the output
    – user6091
    Sep 15, 2009 at 5:25

12 Answers 12


What I did to disable local delivery. I'll be using the example.com domain.


  • example.com A entry pointing to IP address assigned to one of the eth interfaces.
  • /etc/hosts defining example.com assigned to the very same IP address as above
  • example.com MX records pointing to Google servers (ASPMX.L.GOOGLE.COM, etc)
  • default sendmail installation (mine was on Ubuntu)


vim /etc/mail/sendmail.mc

at the end:

define(`MAIL_HUB', `example.com.')dnl
define(`LOCAL_RELAY', `example.com.')dnl

and then:

sendmailconfig (or /etc/mail/make depending on your distro)
service sendmail restart


echo -e "To: [email protected]\nSubject: Test\nTest\n" | sendmail -bm -t -v
echo -e "To: user\nSubject: Test\nTest\n" | sendmail -bm -t -v

You should see it connecting to the google server and then you should see your mail being delivered to your Google inbox.

  • 3
    This worked perfect, i just wonder by there's a . after the domain name.
    – Rod
    Sep 4, 2010 at 4:41
  • Worked flawlessly as well! Jan 26, 2012 at 18:14
  • Thanks! I've been trying to fix this for a while. I did the following; purge and reinstall sendmail, run sendmailconfig, add the lines you specified, run sendmailconfig again and do a service sendmail restart and it works! Jan 10, 2013 at 17:06
  • @Rodrigo example.com. with a trailing dot is a canonical FQDN. The example.com without dot is relative and thus imprecise, for example it could mean example.com.yourdomain.org. depending on your OS settings. This is exactly the same difference as between /etc/passwd and etc/passwd
    – kubanczyk
    Apr 3, 2015 at 20:10

Thanks to sporker and Pawel you put me in the right direction to get this fixed.

My original problem was that sendmail was considering my domain example.com email accounts as local accounts.

These links proved very useful: Sendmail to local domain ignoring MX records (part 2) http://lists.freebsd.org/pipermail/freebsd-questions/2004-September/057382.html http://objectmix.com/sendmail/367920-sendmail-ignores-mailertable-some-semilocal-domains.html

But in my case, using FreeBSD 8.2, what really did the trick was:

# cd /etc/mail

# vim freebsd.mc

Add these two lines:

define(`MAIL_HUB', `example.com.')dnl
define(`LOCAL_RELAY', `example.com.')dnl

Right before:


# make

--- This is output ---

 cp freebsd.mc host.example.com.mc
 /usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/   /usr/share/sendmail/cf/m4/cf.m4 host.example.com.mc > host.example.com.cf
 cp freebsd.submit.mc host.example.com.submit.mc
 /usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/   /usr/share/sendmail/cf/m4/cf.m4 host.example.com.submit.mc > host.example.com.submit.cf

--- End of output ---

# cp sendmail.cf sendmail.cf.bak

# cp host.example.com.cf sendmail.cf

# /etc/rc.d/sendmail restart

Hope this saves some headaches to someone.


I am not a sendmail person but I do believe that sendmail will treat any domain stored in /etc/mail/local-host-names as local domain names.
You could try emptying this file, (do not delete it) and restart sendmail and see how you go.

The filename I mentioned is actually set in sendmail.cf and yours may not be set to local-host-names
look in /etc/mail/sendmail.cf for

# file containing names of hosts for which we receive email 

This is not by any means tested facts but just me thinking out loud.

  • Yep, thats why I already mentioned the domain is not in the local-host-names file
    – user6091
    Sep 15, 2009 at 1:22
  • Sorry, that'll teach me to answer questions I didn't read properly. Sep 15, 2009 at 1:26
  • Had this problem on a set of recently patched Solaris 10 servers (100 or so patched, but only a handful experiencing the problem). This was the fix! Thanks!
    – Signal15
    Apr 15, 2014 at 21:19

If you are using Cpanel/WHM to manage your server, make sure you select Remote Mail Exchanger in Cpanel/WHM instead of Automatically Detect Configuration. Remote Mail Exchanger will send all email via MX records including local domain. With Automatic, local domain emails will directly be routed locally and will not be sent to an external server defined in MX records.


This might not be the solution you're looking for but if your problem is that the "admin" or "root" user is getting a lot of emails and a huge mailbox you may wish to consider setting up a cron job to clear the mailbox out every week, day, etc.

We had several CentOS servers with this issue but the catch was we wanted to be able to read the mail sometimes as it can help diagnose various problems sometimes.

The solution was to simply cron job and wipe the box once in a while.

If we found an issue... we'd comment out the cron job (temporarily) and read through the logs and emails for clues.

Just a thought... and a quick/easy solution for ya.

If not, take a look at the sendmail.mc file and modify accordingly.

Quick update:

This isn't exactly what you're asking for but might give you some ideas and help shed some light on things for you:


  • Sorry that hasn't helped. All I want to do is have no mail delivered locally, why does sendmail make this so hard?
    – user6091
    Sep 15, 2009 at 1:09

I'm personally more of a postfix person, but this sounds very much like you've configured the sending server to receive mail for @yourdomain.com. If there is a sendmail equivalent to the transport mechanism in postfix, that's what I use to route mail internally amongst my servers.

  • I havn't so much configured it, as it was the default for a centos sendmail install.
    – user6091
    Sep 15, 2009 at 3:38

Seems like your Ruleset 3 strips off the domain information. I've included some general troubleshooting steps below. If this does not work, you will have to send me your sendmail.cf to have a look.

From the output, example.com is treated as a local domain. do a nslookup:

set q=mx


If this gives the local machine's ip address then you need to look at your dns. Also look in /etc/hosts to make sure domain.com is not listed.

It also seems to strip off the @domain.com, could you please try with something like [email protected] to see if it also lists it as a local domain.

Also check the Cw value in your sendmail.cf file.

  • Thanks Francois, I'm beginning to understand the sendmail internals a bit better. I've decided to just change the host name of the machine to work around things for now, so it is now www.example.com instead of example.com which means it would do local delivery for [email protected] but not [email protected] - which is an ok compromise for me at this stage.
    – user6091
    Sep 15, 2009 at 20:12

Probably not what you want, but SSMTP is very nice for an outbound only server, where you can specify a mail hub.

  • Thanks, I will give SSMTP a look, still trying to fixup sendmail for now though.
    – user6091
    Sep 15, 2009 at 19:54

If you want to return an error when delivery to a local address is attempted, you can use the access map and something like:

@your.domain error:nouser 550 No such user here

If you want the email messages to be 'delivered' but thrown away, you can install a virtusertable entry that aliases everything for "@your.domain" to dev-null. It may be useful to keep delivering at least "root" locally, because it is often the recipient of email reports from cron jobs etc. Try something like this in your virtusertable:

[email protected] local:root

@your.domain local:dev-null

With a local dev-null alias that redirects messages to /dev/null, this should keep delivering root email, but throw away the messages delivered to other users.


The fix by Pawel worked for me but sendmailconfig didn't exist on centos so I had to run

cd /etc/mail    
m4 /usr/share/sendmail-cf/m4/cf.m4 sendmail.mc > sendmail.cf
service sendmail restart

to get the configuration updated

  • that second rule doesn't work/exist on my centOS
    – solsol
    Nov 8, 2010 at 14:45

Just confirming that Pawel's answer solved my very similar problem.

For anyone using FreeBSD but not interested in getting too involved in sendmail cf file drudgery, the following sequence is what you would use to add the two lines in Pawel's example:

cd /etc/mail
make conf (generates stock .mc/.cf files with the hostname as part of the 
filename - these will NOT be overriten during an upgrade)
vi hostname.mc
(add the two lines to the .mc file right above the last two "MAILER" lines)
make conf
cp hostname.cf sendmail.cf
/etc/rc.d/sendmail restart

I followed these suggestions, and have noticed that just adding the step what pawel mentioned,

"/etc/hosts defining example.com assigned to the very same IP address as above", basically I added my server IP followed by servername to the /etc/hosts file, and that's it.

Was enough for me to get emails routed via google and back to my emails.

You must log in to answer this question.