Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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:

http://serverfault.com/questions/26934/sendmail-configuration-to-not-deliver-mail-to-local-machine

http://serverfault.com/questions/65365/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)
Enter  
> 3,0 info@example.com
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
    
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 '09 at 1:14
    
Try the following: sendmail -bt and then type 3,0 user@domin.com 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

11 Answers 11

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

Requirements:

  • 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)

Steps:

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

testing:

echo -e "To: user@example.com\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

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.

EDIT
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 
Fw/etc/mail/local-host-names

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 at 21:19

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:

MAILER(local)
MAILER(smtp)

# 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.

share|improve this answer

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:

http://www.pettingers.org/code/sendmail-local.html

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 @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.

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 sendmail.cf to have a look.

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

set q=mx

domain.com

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 user@stackoverflow.com to see if it also lists it as a local domain.

Also check the Cw value in your sendmail.cf 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 www.example.com instead of example.com which means it would do local delivery for user@www.example.com but not user@example.com - 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 sendmail.mc > sendmail.cf
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)
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
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

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