Skip to content

How to set up postfix

Postfix is a UNIX mail server. On Beautiful Canoe servers we use it to send security updates and similar to tech@beautifulcanoe.com.

Install postfix

On Ubuntu:

sudo apt-get install postfix

or CentOS:

sudo yum install postfix

Configure postfix

Edit /etc/postfix/main.cf in your favourite text editor and search for [relayhost]. This should be set to:

relayhost = [smtp.aston.ac.uk]

Restart postfix

Restart postfix to apply the configuration changes:

sudo systemctl restart postfix

Open SMTP in the firewall

Ensure that SMTP services can get through the firewall:

sudo ufw allow smtp

Test postfix

To test postfix, send an email from the command line, which requires the mailutils package:

sudo apt-get install mailutils
mail -s Test USER@aston.ac.uk <<<"Test"

and check that the email arrives in your usual mailbox.

Set up the aliases database

If you now look in /var/log/syslog you are likely to see lines like this:

... postfix/local[6576]: warning: hash:/etc/aliases is unavailable. open database /etc/aliases.db: No such file or directory
... postfix/local[6576]: warning: hash:/etc/aliases: lookup of 'root' failed

At this stage, the file /etc/aliases has been created by postfix, but the database /etc/aliases.db has not. To fix this, run postalias:

sudo postalias /etc/aliases

Configure cron jobs to send emails

cron and anacron are UNIX utilities to run commands at specified intervals, usually hourly, daily, weekly or monthly. These utilities are usually used to automate server management tasks such as performing backups and rotating logs.

To configure cron to send email to a mailbox that is likely to be read (rather than root@localhost), edit /etc/crontab and /etc/anacrontab and change the line that starts with MAILTO:

MAILTO=tech@beautifulcanoe.com