If you are not using the latest debian stable or ubuntu LTS, i suggest that you install that first. If you are unable to pick your flavor of the distro version, please keep in mind that some of the below information may not be compatible.

I am going to assume that you have installed a mail server with postfix and now you need spam protection added to it. There are multiple spam filter systems and they can be integrated in various ways with postfix. The most famous antispam filter is of course spamassassin and it’s quite effective for a small setup. Spamassasin can be integrated with postfix over either spampd, amavis or spamassassin-milter. Despite the numerous articles found on the internet about setting up amavis with postfix, i always prefer spamassasin-milter for one simple reason - it by default reduces backscatter emails to almost zero. Not that amavis can’t be made to not generate any backscatter emails, but the most popular amavis integration tutorials configure it in the after-queue filtering mode which is imho a really wrong way to configure it in this spam-laden internet.

In this setup, spamassasin is going to run as a daemon, called spamd. SA-milter will call a client called spamc, which in turn will connect to spamd. When a mail reaches postfix, it will connect to SA milter first, and asks for an spam-check. Based on the result of that check

Let’s install spamassasin and spamassassin-milter first:

 ~#apt install spamassassin spamass-milter

First we’ll configure SA then we will configure SA-milter. Open the file /etc/default/spamassassin and change 'Enabled=0' to 'Enabled=1'

   ENABLED=1
   OPTIONS="--create-prefs --maxchildren 5 -- helper-home-dir"

Edit '/etc/default/spamass-milter' and make sure it contains the following: /etc/default/spamass-milter OPTIONS="-u spamass-milter -i 127.0.0.1"

/etc/init.d/spamassassin
   PATH=/sbin:/bin:/usr/sbin:/usr/bin
   DAEMON=/usr/sbin/spamd
   NAME=spamd
   SNAME=spamassassin
   DESC="SpamAssassin Mail Filter Daemon"
   PIDFILE="/var/run/$NAME.pid"
   export TMPDIR=/tmp
   ENABLED=0
   OPTIONS=""
   NICE=
   . /lib/lsb/init-functions
   test -f /etc/default/spamassassin && . /etc/default/spamassassin
   DOPTIONS="-d --pidfile=$PIDFILE"
/etc/init.d/spamass-milter
   PATH=/sbin:/bin:/usr/sbin:/usr/bin
   NAME=spamass-milter
   DAEMON=/usr/sbin/spamass-milter
   SOCKET=/var/run/spamass/spamass.sock
   PIDFILE=/var/run/spamass/spamass.pid
   DESC="Sendmail milter plugin for SpamAssassin"
   DEFAULT=/etc/default/spamass-milter
   OPTIONS=""
   RUNAS="spamass-milter"
   CHUID=""
   SOCKETMODE="0600"
   SOCKETOWNER="postfix:postfix"

Postfix main.cf should contain this:

   milter_default_action = accept
   milter_protocol = 6
   smtpd_milters = unix:/var/run/spamass/spamass.sock
   non_smtpd_milters = unix:/var/run/spamass/spamass.sock