Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

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 and a web server which is, when I use the smtp service on the web server it currently routes mail to a local mailbox on, but it should be going to mailboxes on

Output of sendmail -bt returns:

ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
> 3,0
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
share|improve this question… 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 '09 at 1:14
Try the following: sendmail -bt and then type 3,0 It will give you a lot of rewrite rules, the last ones should give you the relay it will use. Please provide the output. – Francois Wolmarans Sep 15 '09 at 5:06
Hi Francois, i've edited my question to include the output – user6091 Sep 15 '09 at 5:25

12 Answers 12

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


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


vim /etc/mail/

at the end:

define(`MAIL_HUB', `')dnl
define(`LOCAL_RELAY', `')dnl

and then:

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


echo -e "To:\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.

share|improve this answer
This worked perfect, i just wonder by there's a . after the domain name. – Rodrigo Sep 4 '10 at 4:41
Worked flawlessly as well! – Filipe Pina Jan 26 '12 at 18:14
Worked perfectly, thank you! – Sam V Sep 12 '12 at 3:34
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! – Liam Newmarch Jan 10 '13 at 17:06
@Rodrigo with a trailing dot is a canonical FQDN. The without dot is relative and thus imprecise, for example it could mean depending on your OS settings. This is exactly the same difference as between /etc/passwd and etc/passwd – kubanczyk Apr 3 '15 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 email accounts as local accounts.

These links proved very useful: Sendmail to local domain ignoring MX records (part 2)

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

# cd /etc/mail

# vim

Add these two lines:

define(`MAIL_HUB', `')dnl
define(`LOCAL_RELAY', `')dnl

Right before:


# make

--- This is output ---

 /usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/   /usr/share/sendmail/cf/m4/cf.m4 >
 /usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/   /usr/share/sendmail/cf/m4/cf.m4 >

--- End of output ---

# cp

# cp

# /etc/rc.d/sendmail restart

Hope this saves some headaches to someone.

share|improve this answer

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 and yours may not be set to local-host-names
look in /etc/mail/ 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.

share|improve this answer
Yep, thats why I already mentioned the domain is not in the local-host-names file – user6091 Sep 15 '09 at 1:22
Sorry, that'll teach me to answer questions I didn't read properly. – aussielunix Sep 15 '09 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 '14 at 21:19

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 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:

share|improve this answer
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 '09 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 If there is a sendmail equivalent to the transport mechanism in postfix, that's what I use to route mail internally amongst my servers.

share|improve this answer
I havn't so much configured it, as it was the default for a centos sendmail install. – user6091 Sep 15 '09 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 to have a look.

From the output, 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 is not listed.

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

Also check the Cw value in your file.

share|improve this answer
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 instead of which means it would do local delivery for but not - which is an ok compromise for me at this stage. – user6091 Sep 15 '09 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.

share|improve this answer
Thanks, I will give SSMTP a look, still trying to fixup sendmail for now though. – user6091 Sep 15 '09 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:

root@your.domain 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.

share|improve this answer

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 >
service sendmail restart

to get the configuration updated

share|improve this answer
that second rule doesn't work/exist on my centOS – solsol Nov 8 '10 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)
(add the two lines to the .mc file right above the last two "MAILER" lines)
make conf
/etc/rc.d/sendmail restart
share|improve this answer

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

"/etc/hosts defining 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.

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.