Typo
[linux_from_scratch_hints.git] / OLD / postfix+spamassassin+razor.txt
blob2da10a440a4aa8391ec548fe94955ec89f50cfad
1 TITLE           postfix+spamassassin+razor
2 LFS VERSION     any
3 AUTHOR          Gerard Beekmans <gerard@linuxfromscratch.org>
5 SYNOPSIS
6         Spamassassing and Razor are great spam fighting tools. To make
7 things even better, integrate it into your SMTP server to block spam at the
8 incoming level rather than at the user level through procmail recipies.
10 HINT
12 Version 1.2 - January 15th, 2003
14 Changelog:
16 1.2     - Updated for latest software versions
17         - Using perl daemon for increased performance rather than start the
18           entire perl program for every incoming email.
19         - Removed the spamassassin bug fix from version 1.1
21 1.1     - Added bugfix for the
22           /usr/lib/perl5/site_perl/5.6.1/Mail/SpamAssassin/PerMsgStatus.pm file
24 The main reason I've set it up at linuxfromscratch.org at the SMTP level is
25 to do a spam check before spam hits the mailinglists. Spam is then delivered
26 (I don't send spam by /dev/null by default myself) to Listar, but it's
27 tagged with special headers. Listar checks for these headers and then
28 forwards the spam to me for moderation. This is done just in case an email
29 was marked as spam mistakenly.
31 This hint does not deal with installing the Spamassassin or Razor programs.
32 I'll tell you where to get the software from:
34 Spamassassin:   http://www.spamassassin.org
35 Razor:          http://razor.sourceforge.net
37 Read the docs, install it. It's all very straightforward. I'll just deal
38 with setting it up to work in Postfix.
40 Let's continue with setting up postfix. The postfix distribution comes
41 with the README_FILES/FILTER_README file you want to read through. It
42 gives some background information on how the filtering works in Postfix
43 that we're going to use.
45 That FILTER_README file suggests you creating a dedicated filter user with
46 no home directory or shell. This won't work for us, because spamassassin
47 and razor need a home directory to work in. Perhaps this can be changed, I
48 haven't really checked that out yet. There are probably command line
49 options you can use to use alternate config files (I know Spamassasin's
50 has it, but I'm not sure that it will invoke Razor properly with a
51 different config file).
53 I created a user 'postfixfilter' by running:
55         groupadd -g 612 postfixfilter &&
56         useradd -u 612 -g 612 -m postfixfilter
58 Create the filter script that postfix will be running for every email that
59 comes in:
61 cat /usr/bin/postfixfilter << "EOF"
62 #!/bin/bash
64 /usr/bin/spamc | /usr/sbin/sendmail -i "$@"
66 exit $?
67 EOF
69 Chown and chmod that file if you didn't create it as user postfixfilter but
70 as root or something.
72 What does it do? Postfix dumps an email to /usr/bin/postfixfilter. We
73 intercept it and dump to spamc. Spamc connects to the spamd daemon and will
74 run the spam checking tests, then pipe the rewritten email (now including
75 the spam result headers) to sendmail for continued delivery. It then exits
76 with whatever sendmail's return value was.
78 So, we need to have the spamd daemon running. I added it to the postfix
79 bootscript, using the command "spamd -d -u postfixfilter".
81 Next, configure postfix to do filtering.
83 Edit the /etc/postfix/master.cf (or where ever you keep your postfix
84 configuration files). Find the following line:
86         smtp      inet  n       -       n       -       -       smtpd
88 It may look a bit different but this is the default. This is the line that
89 tells Postfix to listen on the smtp port (25) for incoming email and have
90 smtpd deal with it. This is the one we want to modify to filter that
91 incoming email first before delivering it. Directly below that line, add
92 this one:
94         -o content_filter=postfixfilter:
96 It would be advisable to indent it with a tab or some spaces just so you
97 can easier see that it belongs to the previous line. Do not forget the
98 colon at the end of the postfixfilter. I'm not quite sure what it does, but
99 the FILTER_README file warns to include it, so just do it.
101 Append the following lines to the end of the master.cf file:
103 postfixfilter unix - n n - - pipe
104         flags=Rq user=postfixfilter argv=/usr/bin/postfixfilter -f ${sender} -- ${recipient}
107 Okay, if you did exactly what I told you to do and I didn't forget to tell
108 you anything in this hint, then you are set to go. Reload postfix by
109 running:
111         postfix reload
113 Incoming mail should now be filtered for spam by spamassassin. You can
114 configure spamassassin and razor through the config files in
115 /home/postfixfilter