source: npl/mailserver/dspam/dspam-3.10.2/doc/postfix.txt

Last change on this file was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100644
File size: 8.7 KB
Line 
1$Id: postfix.txt,v 1.0 2009/11/15 20:29:15 sbajic Exp $
2
3POSTFIX INTEGRATION
4
5Please follow the instructions in the README for building DSPAM. Once DSPAM
6has been built, the following instructions may be used to integrate it with
7Postfix.
8
9
10INTEGRATING DSPAM AS A CONTENT FILTER
11
12The most seamless way to integrate DSPAM into Postfix is as a content filter.
13This requires very little work, and allows the two to communicate seamlessly.
14You may want to first read Postfix's FILTER_README from the Postfix source tree
15or online at http://www.postfix.org/FILTER_README.html to familiarize yourself
16with what we're doing. In a nutshell, Postfix sends all mail to the content
17filter instead of delivering it. It's the content filter's job to then pass
18the [modified] message back into Postfix (called reinjection) or do something
19else with the message. By default, DSPAM will quarantine what it believes is
20spam, but it can be configured to tag it instead. We will use DSPAM's LMTP and
21SMTP functionality to integrate the two seamlessly together like so:
22
23[Postfix] (LMTP) -> [DSPAM]                     [Postfix] -> { Delivery }
24                       |___ (SMTP Reinjection) ____|
25
26Step 1: Configure DSPAM as a server daemon
27
28  The first step is to configure DSPAM to listen as an LMTP server on a local
29  UNIX socket. This is what Postfix will connect to when it sends messages to
30  DSPAM. Be sure you have configured DSPAM with the --enable-daemon option.
31  You will need to use an MT-safe storage driver, such as MySQL or PostgreSQL.
32  Once you have DSPAM installed, make the following changes in dspam.conf:
33
34ServerMode              auto
35ServerParameters        "--deliver=innocent"
36ServerIdent             "localhost.localdomain"
37ServerPID               /var/run/dspam.pid
38ServerDomainSocketPath  "/tmp/dspam.sock"
39
40  This will tell DSPAM to listen on /tmp/dspam.sock using the options above.
41
42  You'll also need to configure DSPAM to pass the good mail back into Postfix.
43  Comment out any "TrustedDeliveryAgent" option in dspam.conf and replace it
44  with the options below. We'll use local TCP port 10026 in our example.
45
46DeliveryHost            127.0.0.1
47DeliveryPort            10026
48DeliveryIdent           localhost
49DeliveryProto           SMTP
50
51  This tells DSPAM to deliver using SMTP to port 10026 on the local machine.
52  We'll configure Postfix to listen on this port for reinjection.
53
54  Finally, you'll want to use DSPAM's ParseToHeader option. This option tells
55  DSPAM to automatically train when it sees a spam- or notspam- address in
56  the To: header. Depending on how you have configured DSPAM to manage users,
57  your settings may be slightly different. On a typical setup, where the
58  entire email address is the user's DSPAM username, you would use something
59  like this:
60
61ParseToHeaders          on
62ChangeModeOnParse       on
63ChangeUserOnParse       full
64
65  This means if a user forwards their spam to spam-bob@example.org, the
66  username will be set to bob@example.org and the training mode will be set to
67  "learn spam".
68
69  You can then start DSPAM:  dspam --daemon &
70
71Step 2: Configure Postfix to use a content filter
72
73  The next step is to configure Postfix to use DSPAM as a content filter.
74  This is relatively simple and requires only a minor change to your
75  master.cf file:
76
77  Change:
78
79smtp      inet  n       -       n       -       -        smtpd
80
81  To:
82
83smtp      inet  n       -       n       -       -        smtpd
84  -o content_filter=lmtp:unix:/tmp/dspam.sock
85
86  This tells Postfix to send all mail to DSPAM for content filtering.
87
88  If your Postfix installation is chrooted (as eg. the default Postfix
89  configuration in Debian GNU/Linux), make sure the socket is located
90  within the chroot (eg. /var/spool/postfix/var/run/dspam/dspam.sock).
91
92  Make sure the user under which dspam runs has write access to the
93  socket directory.
94
95  You can also change Postfix configuration so that it does not run
96  chrooted (both smtp and lmtp services should be modified as follows:
97
98smtp      inet  n       -       n       -       -        smtpd
99  -o content_filter=lmtp:unix:/var/run/dspam/dspam.sock
100lmtp      inet  n       -       n       -       -        smtpd
101
102  The 3rd dash specifies if the process will run chrooted or not.
103
104
105 If your SMTP server is also used as a relay, and you want DSPAM to
106 only inspect incoming mail, you can use the following as an alternative
107 to the pure content filtering method:
108
109 You will need Postfix support for PCRE maps (perl compatible regular
110 expression).
111 
112 In Postfix main.cf, add the following to your smtpd_recipient_restrictions:
113
114smtpd_recipient_restrictions =
115  [...]
116  check_recipient_access pcre:/etc/postfix/dspam_filter_access
117
118 where dspam_filter_access contains:
119
120/./ FILTER dspam:dspam
121
122 Add he following service at the end of master.cf:
123
124dspam                 unix    -       n       n       -       -    pipe
125  flags=Ru user=dspam argv=/usr/bin/dspam
126  --client
127  --deliver=innocent,spam
128  --user ${recipient}
129  --mail-from=${sender}
130
131 You will also have to add the following line in main.cf:
132dspam_destination_recipient_limit = 1
133
134
135Step 3: Configure a reinjection port
136
137  You'll also need to configure Postfix to listen on a local port for
138  reinjection. This is where DSPAM sends back the "good" mail (or alternatively,
139  tagged mail also). Add this to your master.cf:
140
141localhost:10026 inet  n -       n       -       -        smtpd
142  -o content_filter=
143  -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
144  -o smtpd_helo_restrictions=
145  -o smtpd_client_restrictions=
146  -o smtpd_sender_restrictions=
147  -o smtpd_recipient_restrictions=permit_mynetworks,reject
148  -o mynetworks=127.0.0.0/8
149  -o smtpd_authorized_xforward_hosts=127.0.0.0/8
150
151  Any mail sent to localhost:10026 will be delivered in whatever way you
152  have configured Postfix, without being passed through DSPAM again. This is
153  also where DSPAM will deliver false positives to when they are retrained by
154  the user.
155
156You're now good to go! Turn on Postfix and do a little testing. Send a message
157to yourself on port 25. It should have X-DSPAM headers. Send a message to
158yourself on port 10026. It should not.
159
160If you are deadset against running DSPAM as a server daemon, this design can
161be changed to call DSPAM via commandline, and have DSPAM reinject by calling
162Postfix's sendmail function. I wouldn't recommend this, but here's how.
163Instead of configuring DSPAM's DeliveryHost and Server options, you'll want to
164configure DSPAM to call sendmail to deliver mail:
165
166TrustedDeliveryAgent    /usr/sbin/sendmail
167Trust postfix
168
169Use the same ParseToHeader options already outlined above. Next, instead of
170having Postfix pass the message to DSPAM via LMTP, you can use:
171
172smtp      inet  n       -       n       -       -        smtpd
173  -o content_filter=dspam:
174
175dspam     unix  -       n       n       -      10        pipe
176  flags=Ruq user=vmail argv=/usr/local/bin/dspam
177  --deliver=innocent
178  --user ${recipient}
179  -i -f ${sender} -- ${recipient}
180
181To avoid users getting a message multiple times when the message contains
182more then one recipient you need to lower the concurrency limit for the
183above mentioned Postfix pipe service to 1. Add this to your main.cf:
184
185dspam_destination_recipient_limit = 1
186
187
188INTEGRATING DSPAM AS A DELIVERY PROXY
189
190Postfix can optionally be configured to integrate with DSPAM as a delivery
191proxy if you're using a third party delivery agent for final delivery to
192your mailbox.
193
194The first step in getting DSPAM to work is to get mail delivery to work with
195one of these external LDAs before integrating DSPAM with Postfix.
196
197You can configure DSPAM with the appropriate LDA using --with-delivery-agent=
198at configure time or by specifying TrustedDeliveryAgent in dspam.conf.
199For example:
200
201TrustedDeliveryAgent    "/usr/bin/procmail"
202
203You'll also want to configure the untrusted delivery agent in a similar
204fashion:
205
206UntrustedDeliveryAgent  "/usr/bin/procmail -d %u"
207
208If you are using maildrop, you'll need to be sure you've compiled maildrop to
209trust the user that DSPAM is running as.
210
211Once you have configured a local delivery agent into DSPAM, the simplest way
212to configure Postfix for local users is to set the mailbox_command directive
213to point to DSPAM. This can be done by editing /etc/postfix/main.cf:
214
215mailbox_command = /usr/local/bin/dspam --deliver=innocent --user $USER -- -d %u
216
217If you're running a delivery agent (such as Cyrus deliver) that has a problem
218with the top 'From' header, you may need to perform some sed magic:
219
220mailbox_command = sed '1{/^From /d;}' | /usr/local/bin/dspam --deliver=innocent --user $USER -- -d %u
221
222Now, configure the aliases as prescribed in the README and you're good to go!
223
224
225CYRUS INTEGRATION
226
227If you're using Cyrus to deliver mail locally, you'll want to specify the
228following in dspam.conf:
229
230TrustedDeliveryAgent "/usr/cyrus/bin/deliver $u"
231
232Then use the following in Postfix:
233
234mailbox_command = /usr/local/bin/dspam --user ${user} --deliver=innocent
235
Note: See TracBrowser for help on using the repository browser.