UPDATE: This guide has been updated to work with Ubuntu 12.04 LTS.
Note: this has been tested to work on the following versions of Ubuntu:- Ubuntu 12.04
- Ubuntu 11.04
- Ubuntu 10.04
- Ubuntu 9.04
This one is mostly for my benefit, but hopefully it’ll be useful to others, too. I’ve tried to make the guide easy to follow and as short as possible. Please comment if something isn’t clear.
Before we start, I have to give a huge amount of credit to Ivar Abrahamsen for his guide which is, by far, one of the best ones out there.
So let’s kick off…
We’ll be building a mail server made up of the following components:
- Postfix is the mail transfer agent (MTA) responsible for accepting new messages and storing them on your server as well as allowing authorised users to send e-mail.
- Courier sits in front of Postfix and provides an IMAP and POP3 interface for clients to connect to.
- SASL with SSL and TLS allows you to authenticate and communicate with the mail server securely.
- SpamAssassin will analyse your e-mails as they arrive and will filter out what it thinks is spam.
- ClamAV will scan e-mails for viruses before delivering it to your inbox.
- Amavis ties SpamAssasin and ClamAV together, and is itself hooked into Postfix.
- MySQL will be used to manage user accounts and e-mail forwarding.
First, switch to the root user unless, of course, you like typing
sudo
.sudo su - |
apt-get update |
Enter a secure password, and don’t forget it!
Similarly, during the installation of Courier you will be presented with the following configuration prompts:
Choose No
Choose OK
Choose Internet Site
Enter your mail server name (e.g. replace example.com with your own domain). Make sure you have this subdomain configured in your DNS records.
Choose OK
I won’t walk you through the parameters we’re using when configuring Postfix as I want to keep this guide light. If you’re interested, you can find more information from the man pages.
mv /etc/postfix/main.cf{,.default} |
myorigin = /etc/mailname |
mv /etc/postfix/master.cf{,.default} |
# |
groupadd virtual -g 5000 |
/etc/postfix/main.cf
, and MYSQL_UID_FIELD and MYSQL_GID_FIELD in /etc/courier/authmysqlrc
(later in this guide).Now we’ll create the database which will store the mail user configuration and forwarding rules.
mysql -uroot -p
|
Copy/paste the following (change mailuserpassword, example.com and change the admin’s password to something more secure):
CREATE DATABASE mail; |
Now that the database is in place we can create the map files to tell Postfix how to communicate with it.
mkdir /etc/postfix/maps |
user=mail |
vi /etc/postfix/maps/domain.cf |
user = mail |
vi /etc/postfix/maps/user.cf |
user = mail |
chmod 700 /etc/postfix/maps/* |
mkdir -p /var/spool/postfix/var/run/saslauthd |
pwcheck_method: saslauthd |
chmod -R 700 /etc/postfix/sasl/smtpd.conf |
START=yes |
vi /etc/pam.d/smtp |
auth required pam_mysql.so user=mail passwd=mailuserpassword host=127.0.0.1 db=mail table=user usercolumn=email passwdcolumn=password crypt=1 |
chmod 700 /etc/pam.d/smtp |
I like to provide both IMAP and POP3 support, although personally I only use IMAP. In addition, we’ll be provide SSL support for securing authentication requests.
mv /etc/courier/authdaemonrc{,.default} |
authmodulelist="authmysql" |
mv /etc/courier/authmysqlrc{,.default} |
MYSQL_SERVER localhost |
mv /etc/courier/imapd{,.default} |
ADDRESS=0 |
mv /etc/courier/imapd-ssl{,.default} |
SSLPORT=993 |
mv /etc/courier/pop3d{,.default} |
PIDFILE=/var/run/courier/pop3d.pid |
mv /etc/courier/pop3d-ssl{,.default} |
SSLPORT=995 |
Run the following (change mail.example.com):
# Remove default certificates |
Next we’ll configure Amavis, the software that ties together SpamAssassin and ClamAV with Postfix.
adduser clamav amavis |
use strict; |
cat /dev/null > /etc/amavis/conf.d/50-user |
use strict; |
mv /etc/default/spamassassin{,.default} |
ENABLED=1 |
dpkg-reconfigure clamav-freshclam |
Choose OK
Choose daemon
Choose a mirror closest to you.
Enter your proxy, if required. Usually you will leave this blank.
By default, ClamAV updates every hour. That’s excessive. Bring that down to once a day.
Choose No
Now restart everything.
/etc/init.d/saslauthd restart |
You can test your setup by configuring your mail client to connect to your new mail server using admin@example.com as your username and the password you chose (“changeme” in the guide).
Errors will usually show up in
/var/log/mail.log
or post any problems you’re having in a comment and I’ll try my best to help.
0 comments:
Post a Comment