In some projects I need to block outbound email but still allow email to a select few domains (or even select few addresses).
As Sendmail comes standard on a lot of Unix operating systems I show here how to set this up. Sendmail handles some of these requirements pretty easy. Additional options like filtering through procmail as well as using Sendmail milters are also good options but not very easy to configure. I did not check but I suspect Linux comes with packages that would make installing python or perl Milter modules easy.
Since Milter packages are not readily available on Solaris and I am focusing on Solaris for this particular project I will use Postfix to meet all the requirements instead of Sendmail + procmail / Milters. I will follow up with a Postfix specific article later since it does better at filtering and relaying than Sendmail.
My use case:
- First block ALL outbound email
- Allow ALL outbound email to two specific domains
- Allow email to very specific email addresses not included in above mentioned two domains
Sendmail handled #1 and #2 pretty easily but it gets overly complicated to allow #1, #2 and #3 at the same time. Below is the configuration for #1 and #2 on Solaris 11.
# pwd/etc/mail/cf/cf
# cp sendmail.mc myhost.mc
# cat myhost.mcdivert(-1)... snip ...divert(0)dnlVERSIONID(`sendmail.mc (Sun)')OSTYPE(`solaris11')dnlDOMAIN(`solaris-generic')dnldnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnlDAEMON_OPTIONS(`Port=smtp,Addr=10.1.10.52, Name=MTA')dnlMASQUERADE_AS(`mydomain.com')FEATURE(masquerade_envelope)FEATURE(`access_db')FEATURE(`mailertable')MAILER(`local')dnlMAILER(`smtp')dnl
# /usr/ccs/bin/m4 ../m4/cf.m4 myhost.mc > /etc/mail/sendmail.cf** You probably don”t need the access feature and local mailer above for this specific configuration. But access might provide more granularity around permissions that might help you.
Setup mailertable. Remember use tabs between left and right columns.
# pwd/etc/mail
# cat mailertabledomain1.com relay:[mail.domain1.com]domain2.com esmtp:%0. local:nobody
# makemap hash mailertable < mailertable** Note above domain1 needed to be passed off to a specific relay on the internal network and domain2 needed to be passed on direct to the Internet.
On Solaris set local_only to false and start senmdail service.
# svccfg -s svc:/network/smtp:sendmail setprop config/local_only = false# svcadm disable svc:/network/smtp:sendmail# svcadm enable svc:/network/smtp:sendmailFrom client setup a smarthost poitning to new server we configured and then test as follow:
# cat /tmp/test.emlTo: user@domain1.comSubject: MAILHOST TEST -> via domain1From: luser@domain.com
body....
# sendmail -d7.99 -d38.99 -vt < /tmp/test.emlMonitor var/log/syslog:
Dec 27 14:44:34 myhost sendmail[6774]: [ID 801593 mail.info] rBRJiYFA006774: from=<root@myclient>, size=554,, nrcpts=1, msgid=<201312271946.rBRJkgq8001045@myclient>, proto=ESMTP, daemon=MTA, relay=myclient [10.1.11.62]Dec 27 14:44:35 myhost sendmail[6776]: [ID 702911 mail.info] STARTTLS=client, relay=mail.arbonne.com., version=TLSv1/SSLv3, verify=FAIL, cipher=AES128-SHA, bits=128/128Dec 27 14:44:36 myhost sendmail[6776]: [ID 801593 mail.info] rBRJiYFA006774: to=<user@domain1.com>, delay=00:00:02, xdelay=00:00:02, mailer=relay, pri=120554, relay=mail.domain1.com. [10.10.1.130], dsn=2.0.0, stat=Sent (<201312271946.rBRJkgq8001045@usla-psag-ag01.prd.asg.ad> [InternalId=15753532] Queued mail for delivery)