【linux】【sendmail】Disable local delivery in Sendmail

转载:http://serverfault.com/questions/65365/disable-local-delivery-in-sendmail/128450#128450

http://vbird.dic.ksu.edu.tw/linux_server/linux_redhat9/0380sendmail.php#theory_mailtrans   (鸟哥sendmail)


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 [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
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 [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. –  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

active oldest votes
up vote 13 down vote

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

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, runsendmailconfig, add the lines you specified, run sendmailconfig again and do a service sendmail restart and it works! –  Liam Newmarch  Jan 10 at 17:06
up vote 1 down vote

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.htmlhttp://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
   
up vote 0 down vote

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
up vote 0 down vote

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
up vote 0 down vote

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
up vote 0 down vote

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 [email protected] 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 [email protected] but not [email protected] - which is an ok compromise for me at this stage. –  user6091  Sep 15 '09 at 20:12
up vote 0 down vote

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
up vote 0 down vote

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.

share | improve this answer
   
up vote 0 down vote

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
up vote 0 down vote

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
   
up vote 0 down vote

@Pawel: thanks for your solution.

But how can I completely 'throw way' them? As my understanding, it is filling up my sendmail queue (~400000). I have to stop the sendmail and manually delete the files in /var/spool/mqueue (sendmail -v -q seem to not work)

Another way, can I disable the local delivery by deleting the line beginning with Mlocal and Mprog in sendmail.cf? I don't know how to edit the sendmail.mc file to remove it. Tried to comment the 4 lines:

dnl define(`PROCMAIL_MAILER_PATH', `/usr/bin/procmail')dnl
dnl FEATURE(`smrsh', `/usr/sbin/smrsh')dnl
dnl FEATURE(local_procmail, `', `procmail -t -Y -a $h -d $u')dnl
dnl MAILER(procmail)dnl

and run m4 but not success.

How can I solve this issue?

share | improve this answer

你可能感兴趣的:(【linux】【sendmail】Disable local delivery in Sendmail)