Table Of Contents

Previous topic

Creating Self-signed Server Certificates

Next topic

Installing Mailman on Ubuntu

This Page

Installing Mail on Ubuntu

Installing Postfix

Getting Postfix installed on Ubuntu can be quite daunting. I have used this quite straight-forward approach honed after being burned a few times.

The Ubuntu images that I use have postfix already installed on them, but usually not Spamassassin. Let’s got Postfix configured first.

Change /etc/postfix/master.cf:

smtp      inet  n       -       -       -       -       smtpd -o content_filter=spamchk:dummy
spamchk   unix  -       n       n       -       -       pipe
    flags=Rq user=filter argv=/usr/bin/spamchk -f ${sender} -- ${recipient}

The spamchk line refers to the script which we will create below, which allows us to configure what happens to spam email.

Edit the /etc/postfix/main.cf to change the domains which postfix will handle, in the mydestination field.

Create a filter user in the filter group:

sudo groupadd filter
sudo useradd -g filter -s /bin/false -d /var/log/spamassassin filter

Create the /usr/bin/spamchk file:

!/bin/sh

# -----------------------------------------------------------------
# File:        spamchk
#
# Purpose:     SPAMASSASIN shell-based filter
#
# Location:    /usr/local/bin
#
# Usage:       Call this script from master.cf (Postfix)
#
# Certified:   GENTOO Linux, Spamassassin 3.0, Postfix
# -----------------------------------------------------------------

# Variables
SENDMAIL="/usr/sbin/sendmail -i"
EGREP=/bin/egrep
SIDELINE_DIR=/home/filter
TMPDIR=/tmp

# Exit codes from <sysexits.h>
EX_UNAVAILABLE=69

# Number of *'s in X-Spam-level header needed to sideline message:
# (Eg. Score of 5.5 = "*****" )
SPAMLIMIT=5

# Clean up when done or when aborting.
trap "rm -f $TMPDIR/out.$$" 0 1 2 3 15

# Pipe message to spamc
cat | /usr/bin/spamc -u filter | sed 's/^\.$/../' > $TMPDIR/out.$$

cp $TMPDIR/out.$$ $SIDELINE_DIR/test-`date +%Y-%m-%d_%R`-$$

# Are there more than $SPAMLIMIT stars in X-Spam-Level header? :
if $EGREP -q "^X-Spam-Level: \*{$SPAMLIMIT,}" < $TMPDIR/out.$$
then
  # Option 1: Move high scoring messages to sideline dir so
  # a human can look at them later:
  # mv $TMPDIR/out.$$ $SIDELINE_DIR/`date +%Y-%m-%d_%R`-$$

  # Option 2: Divert to an alternate e-mail address:
  $SENDMAIL spamsink@tunmer.me < $TMPDIR/out.$$

  # Option 3: Delete the message
  # rm -f $TMPDIR/out.$$
else
  $SENDMAIL "$@" < $TMPDIR/out.$$
fi

# Postfix returns the exit status of the Postfix sendmail command.
exit $?

and set it’s permissions to be owned by filter, and group filter:

chown filter:filter /usr/bin/spamchk
chmod 744 /usr/bin/spamchk

Installing Spamassassin

Since this isn’t installed by default, use apt-get to install it:

sudo apt-get install spamassassin spamc

Create the group and user spamd:

sudo groupadd spamd
sudo useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd
sudo mkdir /var/log/spamassassin
sudo chown spamd:spamd /var/log/spamassassin

Edit /etc/default/spamassassin so these options are set:

ENABLED=1

SAHOME="/var/log/spamassassin/"

OPTIONS="--create-prefs --max-children 2 --username spamd -H ${SAHOME} -s ${SAHOME}spamd.log"

–max-children spawns the specified number of child processes (you might need more on a busy server), –username specifies the username spamd runs under, -H sets the home directory, -s sets the log file.

Start the spamd service:

/etc/init.d/spamassassin start

and reload the postfix service:

sudo /etc/init.d/postfix reload

Installing Dovecot

If it’s not installed already, run:

sudo apt-get install dovecot-imapd dovecot-pop3d

Edit /etc/dovecot/dovecot.conf. The protocols should be set up to use imap, pop3 and sieve.