March 2, 2013, midnight

# Setup a mail server with Ubuntu and Postfix

## Considerations

• The ip address used is 106.187.102.92
• The machine hostname is hercules
• The domain is voorloopnul.com
• You have to change those values to reflect your setup

## Requirements

• Ubuntu 12.10, but any recent debian based distro should work without much modification.
• A VPS or a physical server
• You must be able to setup the dns using the tools provided by your host provider

## Install the packages

The list of packages required are not so extensive:

 apt-get install libsasl2-2 libsasl2-modules sasl2-bin postfix dovecot-postfix postgray openssl


During the installation process, the package manager will ask for some input about the initial setup of postfix:

## Setup the SASL authentication mechanism

Edit the file /etc/default/saslauthd and set it to start as a regular daemon:

START=yes


Start the sasl daemon:

service saslauthd start


Create the file /etc/postfix/sasl/smtdp.conf with the following content:

pwcheck_method: saslauthd


## Create a SSL/TLS certificate

Type the following to generate the certificate and fill the blanks like the screenshot:

openssl req -new -x509 -days 365 -nodes -out /etc/ssl/certs/ssl-mail.pem -keyout /etc/ssl/private/ssl-mail.key


365 is the number of days before you need to renew your certificate. If you want that your certificate last longer, fell free to change this value.

## To setup dovecot edit the file /etc/dovecot/conf.d/01-mail-stack-delivery.conf

Disable the protocol pop3 and sieve:

- protocols = imap pop3 sieve
+ protocols = imap


Enable the maildir format with all the email centralized in /var/mail instead of being in the user home:

- mail_location = maildir:~/Maildir
+ mail_location = maildir:/var/mail/%u


Last you add the following content at the bottom of the file:

  service imap-login {
inet_listener imap {
port=0
}
}


The result will look like this:

## To setup postfix edit some lines in /etc/postfix/main.cf

Comment or remove the keyword home_mailbox

- home_mailbox = Maildir/


Set myhostname with the FQDN

+ myhostname = hercules.voorloopnul.org


Tell postfix where to save messages, it will be override by the dovecot configuration.

+ mail_spool_directory = /var/mail


You have to add the line checkpolicyservice inet:127.0.0.1:10023 to the smtpdrecipientrestrictions keyword. This will make postgrey work with postfix

smtpd_recipient_restrictions = ...,
...,
...,
check_policy_service inet:127.0.0.1:10023


For clarity I removed all commented text from my file. As you can see most of the config was untouched, the final result looks like this:

## DNS Requirements

• mx record
• a record for mail.voorloopnul.com
• spf record
• reverse entry