Postfix Mail Server configuration tutorial

09 March 2013
By Gonçalo Marques
In this tutorial you will learn how to deploy a simple configuration of Postfix Mail Server.


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:

  1. Ubuntu 12.10
  2. Postfix 2.9.6

Install Postfix

We start by installing Postfix. Issue the following command in the console:

apt-get install postfix

Now we may also install a simple SMTP client like mailutils so we can test the configuration at the end:

apt-get install mailutils


One of the most important Postfix configuration files is The file is usually located at:

Edit the file and add the following lines where is your mail domain:

myhostname =
mydestination = localhost.$mydomain, localhost

Uncomment the following lines:

home_mailbox = Maildir/
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases

Comment the following lines:

setgid_group =
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:

groupadd -g 5000 vmail
useradd -m -u 5000 -g 5000 -s /bin/bash vmail

Configuring mail directories in

We go back again to /etc/postfix/ and add the following lines:

virtual_mailbox_domains = /etc/postfix/vhosts
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:

Insert your mail domains in the file, one domain per line:

Creating mailboxes

Edit the file:

Insert as much users you need in this file - one user per line - following the pattern:

[email protected]

All mail that is sent to [email protected] will be stored in directory.

Generate mail database file

Now we generate the mail database file by issuing the following command in the console:

postmap /etc/postfix/vmaps

After this step you should a mail database file at:


Start Postfix and testing

We may start Postfix now by issuing the following command:

service postfix start

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:


Related Articles


About the author
Gonçalo Marques is a Software Engineer with several years of experience in software development and architecture definition. During this period his main focus was delivering software solutions in banking, telecommunications and governmental areas. He created the Bytes Lounge website with one ultimate goal: share his knowledge with the software development community. His main area of expertise is Java and open source.

GitHub profile:

He is also the author of the WiFi File Browser Android application: