MikeL's FreeBSD howto - Milter
[20200512]
I no longer recommend this - just use SpamAssassin.
If you get anywhere near as much spam junk as I get, you need
to use Milter! Here's some
details to get it going...
The following example is for
milter-regex, a
"port" in FreeBSD which I use and recommend. Don't bother asking me
about any others, as this is the only one I've ever used...
Build/install:
cd /usr/ports/mail/milter-regex/
su
(and password)
make
make install
milter-regex installation doc is in it's man page (man 8
milter-regex)
On your server, you need to make the following config changes:
- (In modern FreeBSD, the default is for sendmail to have already
been compiled with milter enabled. If the package you're using
gives you instructions on doing this, you may simply skip this
step on FreeBSD.)
- You should be using M4 for sendmail config. If not, this is the
time to make the change. Trust me, it's worth it.
- In your .mc file, you'll add something like the following:
INPUT_MAIL_FILTER(`milter-regex', `S=unix:/var/spool/milter-regex, T=S:30s;R:2m')
This example is for milter-regex. The specific incantation for
the package you've chosen will be in it's documentation.
A note on .mc files: Anything following a "dnl" is a
comment. You do not need a trailing "dnl" on .mc file lines,
regardless of how many examples of this you see on the web. You can
test this yourself, by 'make'ing your config file, then removing all
trailing "dnl"s, remaking the file and 'diff'ing them.
- As described in the manpage, modify your
/etc/rc.conf
adding:
milter_regex="YES"
milter_flags="-c /etc/mail/milter-regex.conf"
- As described in the manpage, modify (or create if non-existant)
your
/etc/rc.local
adding:
if [ X"${milter_regex}" == X"YES" -a \
-x /usr/local/libexec/milter-regex ]; then
echo -n ' milter-regex'
/usr/local/libexec/milter-regex ${milter_flags}
fi
Note! I've added the "milter_flags" var, and am specifying a
config file location other than the default.
- Build yourself a milter-regex file. For testing purposes I
whipped up the following, in memorium of the Internet's earliest
(to have notoriety) spammer:
#
# milter-regex file vintners.net MikeL 12-Nov-2003
#
reject Rejected, spamvertised website "cyberpromo.com"
body ,http://[^/]*cyberpromo\.com/,i
Testing your config:
- Start milter-regex (I'd recommend following the Troubleshooting
steps below).
- Send yourself an email containing an offending pattern.
Simply going to the commandline and invoking 'sendmail -t' and
slapping out that message will do just fine.
brix# sendmail -t
To: <your-email-addr>
From: <your-email-addr>
Subject: testing
<blank line>
http://www.cyberpromo.com/
<hit Ctrl-D>
brix#
- Check your mailbox for bounce message or other appropriate
behaviour depending upon your rules.
- Check your logs (
/var/log/maillog
) -- search for
reject=
. If it's working, you'll see "reject="
entries corresponding to the milter rules you've set up. In my
sample above, "reject=554" will do nicely.
Troubleshooting:
- As described in the manpage, start milter-regex from a commandline
with the '-d' switch. It will then say:
started
calling smfi_main()
and then just sit there until an email arrives. You'll know it when a mail arrives as it will display what's happening, starting with:
cb_connect(...)
loading configuration file
etc.
- (Just a note -- milter-regex appears to check for a
config file change each time it gets an email to process. If
there's been a change, it will then slurp it in.)
- If you don't see immediate activity upon sending yourself the test
email, you probably (one or more of):
- Forgot to '
make
' after changing the .mc file in
/etc/mail/
- Forgot to copy generated .cf file into
'
sendmail.cf
'
- restart sendmail
- Hit Ctrl-C to quit interactive mode. Give it a moment
-- After a few seconds, app will quit saying
"
terminating gracefully
".
Copyright © 1995-2024
Mike Lempriere
(running on host bayanus)