sal-wrapper.pl: configuration examples
In the following sections you will find some examples about how to use sal-wrapper.pl
How to use it with postfix (top)
In the following I will describe how to use sal-wrapper.pl with postfix. This setup is mainly, but not only, used on a mail gateway. This will only work if you have just one user which runs your spamassassin and which scans all passing emails.
Download sal-wrapper.pl and store it somewhere (/path/to/sal-wrapper.pl)
You need two accounts on your mailserver: »spam« and »ham«. You can realize this by adding the following lines to your alias (default: /etc/aliases) file:
-
ham: postmaster
spam: postmasterAdd the following two lines to your master.cf (default: /etc/postfix/master.cf) file:
-
sa-wrapper unix - n n
- - pipe
user=vscan argv=/path/to/sal-wrapper.pl --${mailbox}replace the user »vscan« with the user which runs your spamassassin and replace '/path/to/sal-wrapper.pl' with the path to the script. If you use spamc as your learning client, then replace
--${mailbox}
with-L ${mailbox}
. Restart postfix.Enable the use of a transport table by specifing the following in your main.cf file:
-
transport_maps = hash:/etc/postfix/transport
And add the following to your transport table:
-
spam@your.server.tld sa-wrapper:
ham@your.server.tld sa-wrapper:Then don't forget to rebuild the map with postmap transport.
Create the needed logfile and directory:
-
touch /var/log/sa-learn.log
chown vscan:log /var/log/sa-learn.log
chmod 644 /var/log/sa-learn.log
mkdir /var/spool/unpack
chown root:vscan /var/spool/unpack
chmod 774 /var/spool/unpackEdit spamassassin's local.cf file (default: /etc/mail/spamassassin/local.cf) and activate bayes.
use_bayes 1
use_bayes_rules 1
bayes_auto_learn 1It may be worth to use a restriction table in Postfix to prevent outside MTAs to deliver mails to the »spam« and »ham« accounts. The sal-wrapper Script is by itself capable to discard mails from outside, so the following step is not absolutly necessary.
The the below given code shows an example of how to change the recipient restrictions in Postfix's main.cf to reject mails from outside to the »spam« or »ham« addresses:
smtpd_recipient_restrictions =
...
permit_mynetworks
permit_sasl_authenticated # only if you use sasl
check_recipient_access hash:/etc/postfix/recipient_access.outside
...
Create the file /etc/postfix/recipient_access.outside and add this content:
spam@your.server.tld REJECT 5.2.1 recipient unavailable from outside
ham@your.server.tld REJECT 5.2.1 recipient unavailable from outsideDon't forget to execute: postmap /etc/postfix/recipient_access.outside
Now you can put your spam messages in the appendix of a new mail and send it to spam@your.server.tld. The same with your ham mails, put them in the appendix of a new message and send it to ham@your.server.tld.
How to use it with Postfix (alternative) (top)
This alternative method uses a second aliases map to run the sal-wrapper script. Create a new aliases map whose owner is the user which runs spamassassin.
Download sal-wrapper.pl and store it somewhere (/path/to/sal-wrapper.pl)
Then create a new aliases file and change the user (this ist important because the commands in the aliases file will run with the privileges of the file owner).
# touch /etc/report_aliases
# chown YOUR_USER /etc/report_aliasesThen add the following content to the new aliases map. If you use spamc as your learning client, then replace
--${mailbox}
with-L ${mailbox}
.spam: "|/PATH/TO/sal-wrapper.pl --spam"
ham: "|/PATH/TO/sal-wrapper.pl --ham"Then add the report_aliases map to alias_maps in main.cf:
...
alias_maps = hash:/etc/aliases, hash:/etc/report_aliases
...Create the new aliases database and reload Postfix:
# postalias /etc/report_aliases
# /sbin/rcpostfix reloadPrevent outside clients to send messages to your »spam« and »ham« accounts. See: add a restriction table
How to use it with procmail (top)
Unfortunately I don't use procmail by my self, so I just copied the procmail.rc script from huschi.net. This will be useful if you run SpamAssassin on a per user basis and if you have the user accounts locally on your server.
~/procmail.rc:
VERBOSE=ON
LOGFILE=/var/log/procmail.log
:0
* ^To: spam@your.server.tld
{
:0fw
| /usr/local/bin/sa-wrap.pl --spam
:0
/dev/null
}
:0
* ^To: ham@your.server.tld
{
:0fw
| /usr/local/bin/sa-wrap.pl --ham
:0
/dev/null
If you use spamc as your learning client, then replace --${mailbox}
with -L ${mailbox}
.