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/

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/ 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:


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

# Variables
SENDMAIL="/usr/sbin/sendmail -i"

# Exit codes from <sysexits.h>

# Number of *'s in X-Spam-level header needed to sideline message:
# (Eg. Score of 5.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.$$
  # 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 < $TMPDIR/out.$$

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

# 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:



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.