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

I was wondering if you could please help me with what could be a simple problem but i cant seem to figure it out.

We have a few centos servers running sendmail (all internal servers on the local lan)- with a very simplistic sendmail configuration (all default) except for a relay everything to our exchange server option i.e DSourexchangeserver Now what i want to do is have these centos servers sendmail configurations ONLY relay emails destined for our companys domain i.e me@mycompaniesdomain.com I do not want mail relayed to anywhere else. Is there anyway to get sendmail to check mails being passed to it and only relay ones on to our exchange server that meet the requirement of being destined for our companies domain and stop everything else ?

share|improve this question

4 Answers 4

See: http://www.sendmail.org/tips/relaying

The simplest approach is to list the domains you are willing to relay in the file /etc/mail/relay-domains. Anything listed in this file will be accepted for relaying. N.B.: Sendmail must be restarted after this file is modified.

This and other tips on that page should get you started. Otherwise, you may want to check into SMTP AUTH if you need to control who can relay email.

share|improve this answer
    
Relay-domains is what you want. Put your companies name in there and disable all other relaying. –  jeffatrackaid Dec 20 '11 at 21:12
    
this is not what i need and doesnt work, im going to ask another question about using a milter , this can be deleted. –  user104716 Dec 22 '11 at 2:40

The problem with relay-domains is that it permits relaying if the sending system is in that domain.

Using an access database may be the solution. In it put:

To: mycompaniesdomain.com RELAY

Be sure to have all other relay options off. Sendmail is a complex beast and it may be good to post your mc file.

share|improve this answer
    
mc is too long to post but here are the relevant parts i added from adamos suggestions : define(SMART_HOST', myexchangeserver') C{Exchange} mydomain.com LOCAL_RULE_0 R$* < @ $=w . > $* $#OK R$* < @ $={Exchange} . > $* $#OK R$* $#local $: bit-bucket –  user104716 Feb 9 '12 at 1:58
    
dont worry about the backtick syntax so much - that is correct - i just dont know how format the comment correctly with mini-markdown. However any help with the actual syntax of what im doing would be much appreciated. –  user104716 Feb 9 '12 at 2:05

You do not need a milter for that. You can do it via sendmail.mc. Add these lines in your sendmail.mc:

#Define the smart host
define(`SMART_HOST', `exchange server here')dnl

#Define a class of domains we want to relay to the smart host
C{Exchange} example.com example.org

#Decide whether to delete outgoing email or not
LOCAL_RULE_0
#test the behavior of your system to see if you need the following line
R$* < @ $=w . > $*              $#OK
R$* < @ $={Exchange} . > $*     $#OK
R$*                             $#local $: bit-bucket

bit-bucket should be aliased to /dev/null in /etc/mail/aliases:

bit-bucket: /dev/null

Remember to rebuild sendmail.cf from the sendmail.mv file afterwards and restart sendmail. I do not know how this is done in CentOS. Debian's sendmailconfg has made me a little lazy. Also remember that sendmail rules are divided with tabs and not spaces so do not copy-paste. Type by hand and separate the "left" and "right" parts after LOCAL_RULE_0 with tabs.

share|improve this answer
    
This looks good adamo, and looks what i want to do but when i make the changes - regenerate sendmail - then start the daemon i get an error saying : 451 4.0.0 /etc/mail/sendmail.cf: line 63: fileclass: cannot open 'domain_i_want_mail_sent_to.com': No such file or directory Is there a file i have to create ? Thanks for your help –  user104716 Jan 12 '12 at 23:06
    
My mistake! Change F{Exchange} to C{Exchange}. C stands for class definition within the configuration file, while F stands for class definition from an outside file. I've edited my answer accordingly. –  adamo Jan 13 '12 at 6:38
    
Thanks adamo! , however now i get the following in maillog whenever i try to send an email anywhere : Jan 16 10:33:39 myserver sendmail[3213]: q0FLXd3Z003213: from=myuser, size=49, class=0, nrcpts=1, msgid=<201201152133.q0FLXd3Z003213@myserver.my.domain>, relay=myuser@localhost Jan 16 10:33:39 myserver sendmail[3214]: q0FLXdMU003214: SYSERR(root): buildaddr: no user Jan 16 10:33:39 myserver sendmail[3213]: q0FLXd3Z003213: to=blah@gmail.com, ctladdr=myuser (4686/100), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30049, relay=[127.0.0.1] [127.0.0.1], dsn=5.0.0, stat=Service unavailable –  user104716 Jan 15 '12 at 21:37
    
maybe it has something to do with the bit-bucket alias ? i didnt actually have an /etc/mail/aliases file so i made it and just added bit-bucket: /dev/null is that ok ? –  user104716 Jan 15 '12 at 21:46
    
If it is not in /etc/mail/aliases, then it must be in /etc/aliases. After editing the aliases file you have to rebuild the aliases database by running newaliases –  adamo Jan 16 '12 at 10:22
up vote 0 down vote accepted

This is how i set it up :

1 sendmail server that all email from nix machines goes to and gets relayed to the exchange server depending on where the email is bound for.

All clients sendmail configs have a DS option for the server above.

On the 1 sendmail server (that all your sendmail configs will point to for the DS option that will act as the filter do the following :

  1. Make sure in sendmail.mc under /etc/mail it has the : Feature('mailertable', 'hash -o /etc/mailertable.db' dnl line in it.

  2. Comment out the line that says DAEMON_OPTIONS(``Port=smtp,Addr=127.0.0.1, Name=MTA')dnl (so that it can relay for all machines - obviously this wouldnt be a good idea for a machine that has a public IP - but thats not what im doing here)

  3. vi mailertable and put in the following line : yourdomain.com ESMTP:[yourexchangeserverip]

  4. Create a file under /etc/mail called relay-domains and put in the following line : yourdomain.com

  5. Run m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

  6. Run makemap hash /etc/mail/mailertabledb < /etc/mail/mailertable

  7. start or restart the sendmail daemon , /etc/init.d/sendmail restart

Then on all the machines you want to have email filter for just go into the sendmail.cf and set the DS option to the ip or hostname of your server above. Then restart sendmail.

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.