Setting up the spamassassin anti-spam service on the Ubuntu\Debian mail server for the Postfix service and moving emails to the Spam folder. This configuration allows you to make working with mail comfortable by training the filter and automatically moving messages.
This guide assumes that you have already configured the mail server itself and that you need to configure the spam filter. More information about setting up a mail server can be found here:
You can also order a VPS with a pre-configured operating system and get a ready-made corporate mail server for the price of a VPS server.
1. Install the service spamassassin
apt-get install spamassassin spamc
adduser spamd --disabled-login
2. Let's set up the service
vi /etc/default/spamassassin
Find the line:
OPTIONS="--create-prefs --max-children 5 --helper-home-dir"
and replace with:
OPTIONS="--create-prefs --max-children 5 --username spamd --helper-home-dir /home/spamd/ -s /home/spamd/spamd.log"
At the very end of the file, include cron:
CRON=1
Let's save the file. (:wq)
3. Filter setting:
mv /etc/spamassassin/local.cf /etc/spamassassin/local.cf.bk
vi /etc/spamassassin/local.cf
rewrite_header Subject ***** SPAM SCORE *****
report_safe 0
required_score 5.0
use_bayes 1
use_bayes_rules 1
bayes_auto_learn 1
skip_rbl_checks 0
use_razor2 0
use_pyzor 0
ifplugin Mail::SpamAssassin::Plugin::Shortcircuit
endif
Let's save the file.
4. Configuring the Postfix Service
Find the smtp line and add the configuration below:
vi /etc/postfix/master.cf
smtp inet n - y - - smtpd -o content_filter=spamassassin
spamassassin unix - n n - - pipe
user=spamd argv=/usr/bin/spamc -f -e
/usr/sbin/sendmail -oi -f ${sender} ${recipient}
Save the file and restart the services
systemctl restart postfix.service
systemctl enable spamassassin.service
systemctl start spamassassin.service
Let's check the operation of the service by sending a letter containing this text to the mailbox:
XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X
5. Set up moving spam emails to the Spam folder.
Install and configure the Sieve service
apt-get install dovecot-sieve dovecot-managesieved
vi /etc/dovecot/conf.d/90-sieve.conf
sieve = /etc/dovecot/dovecot.sieve
Let's save the file.
Let's create a file:
vi /etc/dovecot/dovecot.sieve
require "fileinto";
if header :contains "SPAM" "YES" {
fileinto "Junk";
}
if header :contains "X-Spam-Flag" "YES" {
fileinto "Junk";
}
Let's save the file.
Add the configuration to the end of the file:
vi /etc/dovecot/dovecot.conf
service stats {
unix_listener stats-reader {
user = vmail
group = vmail
mode = 0660
}
unix_listener stats-writer {
user = vmail
group = vmail
mode = 0660
}
}
Let's save the file.
Let's add the configuration to the file so that the line looks like this:
vi /etc/dovecot/conf.d/15-lda.conf
protocol lda {
mail_plugins = $mail_plugins sieve
}
Let's add the configuration to the file so that the line looks like this:
vi /etc/dovecot/conf.d/10-director.conf
protocol lmtp {
mail_plugins = $mail_plugins sieve
}
Let's restart the services:
systemctl start spamassassin.service
systemctl restart postfix.service
Now all emails marked as spam will appear in the Spam folder.