Postfix Mail Server configuration tutorial
Introduction
Postfix is an open source MTA or SMTP server. In this tutorial we will deploy a very simple configuration of Postfix. We will see in other tutorials how we can deploy more complex configuration including user authentication, SSL and message signing.
This tutorial considers the following software and environment:
- Ubuntu 12.10
- Postfix 2.9.6
Install Postfix
We start by installing Postfix. Issue the following command in the console:
Now we may also install a simple SMTP client like mailutils so we can test the configuration at the end:
Configure main.cf
One of the most important Postfix configuration files is main.cf. The file is usually located at:
/etc/postfix/main.cf.
Edit the file and add the following lines where domain1.com is your mail domain:
mydestination = localhost.$mydomain, localhost
Uncomment the following lines:
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
Comment the following lines:
sendmail_path =
mailq_path =
newaliases_path =
manpage_directory =
sample_directory =
readme_directory =
html_directory =
Creating mailbox owner
Now we need to configure the mailbox owner. Create the user and the respective group by issuing the following command in the console:
useradd -m -u 5000 -g 5000 -s /bin/bash vmail
Configuring mail directories in main.cf
We go back again to /etc/postfix/main.cf and add the following lines:
virtual_mailbox_base = /home/vmail
virtual_mailbox_maps = hash:/etc/postfix/vmaps
virtual_minimum_uid = 1000
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
biff = no
append_dot_mydomain = no
Creating domains
Edit the file:
/etc/postfix/vhosts
Insert your mail domains in the file, one domain per line:
Creating mailboxes
Edit the file:
/etc/postfix/vmaps
Insert as much users you need in this file - one user per line - following the pattern:
All mail that is sent to [email protected] will be stored in domain1.com/user/ directory.
Generate mail database file
Now we generate the mail database file by issuing the following command in the console:
After this step you should a mail database file at:
Start Postfix and testing
We may start Postfix now by issuing the following command:
After the service is started we may use mailutils to test if the mail server is ok. If you already installed mailutils you may issue the following command in the console:
You will be asked to insert Cc (carbon copy). You may leave it empty and press ENTER. Now insert the Subject and press ENTER again. Finally insert your message text and press ENTER to go into a new empty line and then press Ctrl+D to send the message.
If everything went OK you should have a new mail message in:
Configuring a mail server can be problematic especially if you are doing it for the first time. Postfix has a robust logging mechanism and by looking at the logs you can almost certainly check what went wrong. The log file is located at: