If your server was upgraded from "Etch"
If your server has been upgraded from a former Debian 4.0 "Etch" installation then you may need to fix two files. First make sure that your /etc/hostname contains the host name without the domain part. It does that on Lenny by default but if you are upgrading from a previous "Etch" installation then this may be wrong. The file /etc/mailname is supposed to contain the fully-qualified host name with the domain part.
Your /etc/hosts may also need to be fixed. Run hostname --fqdn and see if you get the fully-qualified hostname. If you just get the hostname without the domain please check that your /etc/hosts file has the fully-qualified hostname first in the list.
18.104.22.168 mailserver42 mailserver42.example.com
22.214.171.124 mailserver42.example.com mailserver42
Then begin by installing Postfix with MySQL backend support:
$> aptitude install postfix-mysql
This will also install the postfix package automatically. Exim (the default mail service installed with a fresh installation) will be removed. When asked for the general type of configuration choose "Internet Site". Answer the question for the "System mail name" by entering the fully qualified hostname of your system.
Run this line on the system to install the MySQL server:
$> aptitude install mysql-server
Note: You can run MySQL server on the same system as your actual mail service - but don't have to. The mail server can communicate with the MySQL server via TCP networking. During the installation you will get asked for the password of a newly created "root" user. This is not your system administrators login account but a special user to access the MySQL server. Choose any password you want and write it down. And another warning: during the installation a MySQL user account called "debian-sys-maint" will be created with a random password. The password is stored in the /etc/mysql/debian.cnf file. Do not touch this file or change the user's password in the database or you won't be able to stop or start the MySQL service any more.
You will want to offer POP3 and IMAP services to your users so you need to install Dovecot's services:
$> aptitude install dovecot-pop3d dovecot-imapd
Some of the packages needed to scan for virus-infected attachments are not "free enough" to be included in Debian's main section (e.g. "unrar" or "lha"). If you want to install them you first need to add the non-free section to your Debian mirrors in the /etc/apt/sources.list file. You usually just need to add "non-free" to your existing mirror lines for the Debian archive like this:
deb http://ftp.debian.org/debian/ lenny main non-free
$> aptitude update
to update your package cache with the list of "non-free" packages.
It's a good service to your users to filter out spam and viruses for them. AMaViS is doing a good job here to detect unwanted emails:
$> aptitude install amavisd-new spamassassin clamav-daemon lha arj \
unrar zoo nomarch cpio lzop cabextract
AMaViS is now installed with a number of suggested packages to scan attachments for viruses and detect spam.
If you intend to offer a webmail service I can recommend the Squirrelmail package. It will automatically install the Apache web server if you do not yet have one installed. Type:
$> aptitude install squirrelmail
As your control information for Postfix will be stored in a MySQL database you may want to install the PhpMyAdmin software that allows you to manage the database and its data in your web browser:
$> aptitude install phpmyadmin
(If you get asked which web server to configure you will probably want to choose "apache2".)
The console-based mutt email client lets you read mail from mailboxes directly from the hard disk. It will be helpful for testing the configuration. And it's even a very powerful IMAP email client that many people use as their main mail program. Maybe you'll start to like it, too. You should install it at least for testing:
$> aptitude install mutt
Now all basic packages are installed and it's time to prepare the database in the next chapter.