May 082012
Article Postfix

(Leer este artículo en español)

In a previous post we explained how to perform the installation of the Postfix mail server.

In this post we will explain how to install Postfixadmin. Postfixadmin is a web frontend to the mysql database used by Postfix. With Postfixadmin we can easily manage from a web browser our Postfix service, adding and removing mail users and domains, mail aliases, disk quotas, etc.

First we download the gzipped Postfixadmin package from sourceforge. The filename we downloaded is ‘postfixadmin-2.3.5.tar.gz’

Once the package has been downloaded, we uncompress it (as root user) under the directory ‘/usr/share’, and create a symlink:

# cd /usr/share
# tar -xvzf ~/downloads/postfixadmin-2.3.5.tar.gz
# ln -s postfixadmin-2.3.5 postfixadmin

Next, we edit the config file /usr/share/postfixadmin/ to specify the details of our setup. We must edit the mysql database name, and the username/password to access it:

$CONF['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfix';
$CONF['database_password'] = 'write-here-your-password';
$CONF['database_name'] = 'postfix';

Then, we proceed to create the database:

root@openalfa:/usr/share/postfixadmin# mysql -u root -p
Welcome to the MySQL monitor.  Commands end with ; or g.

mysql> create database postfix;
Query OK, 1 row affected (0.00 sec)

mysql> create user postfix@localhost identified by 'write-here-your-password';
Query OK, 0 rows affected (0.07 sec)

mysql> grant all privileges on postfix.* to postfix;
Query OK, 0 rows affected (0.00 sec)

mysql> quit

Next, we add an Alias directive in the configuration file of our apache web server:

Alias /postfixadmin /usr/share/postfixadmin

and restart the web server. Now we can access from a browser the url http://localhost/postfixadmin/setup.php:

PostAdmin setup screen

In this screen, we introduce the setup password that we had previously configured in the postfixadmin config file ($CONF[‘setup_password’] ), and the email address and password of the admin user to be created.

When we submit the form for the first time, we get an error message about the setup password not matching, and a “hashed password” that we must copy, and paste as the value of the variable “$CONF[‘setup_password’]” in the postfixadmin configuration file.

Once this is done, we submit again the form, and this time we receive a success message “Admin has been added!”

Now we can access the login form at the url  to administer our mail server:

Pantalla de login de postfixadmin

After login in, we reach the main admin screen:

Pagina principal de postfixadmin

How to configure Postfix to use the Postfixadmin mysql database

After completing the previous steps, we are able to access the Postfixadmin frontend and define virtual mailbox domains and users, and mail aliases.

But Postfix admin just stores this information in the mysql database, and we must tell Postfix to read this information from the Postfixadmin database.

We do this creating (with your text editor of choice) four files under the directory ‘/etc/postfix’.

1. /etc/postfix/

user = postfix
password = write-here-your-password
hosts =
dbname = postfix
table = alias
select_field = goto
where_field = address

2. /etc/postfix/

user = postfix
password = write-here-your-password
hosts =
dbname = postfix
table = domain
select_field = domain
where_field = domain
#additional_conditions = and backupmx = '0' and active = '1'

3. /etc/postfix/

user = postfix
password = write-here-your-password
hosts =
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
#additional_conditions = and active = '1'

4. /etc/postfix/

user = postfix
password = write-here-your-password
hosts =
dbname = postfix
table = mailbox
select_field = quota
where_field = username
#additional_conditions = and active = '1'

To make sure that these files are only readable by root, we execute:

# chgrp postfix /etc/postfix/mysql_*.cf
# chmod 640 /etc/postfix/mysql_*.cf


Create a ‘vmail’ user

To avoid creating a different userid for each of the mail users we are going to define in our server, we must create a unix user “vmail”, that will be the owner of all the files of our virtual mail users:

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

Next we edit ‘/etc/postfix/’ to tell postfix to use the previously created files, adding the lines:

# Virtual mailbox configuration
virtual_alias_maps = mysql:/etc/postfix/
virtual_mailbox_domains = mysql:/etc/postfix/
virtual_mailbox_maps = mysql:/etc/postfix/
virtual_mailbox_limit = 51200000
virtual_minimum_uid = 5000
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
virtual_mailbox_base = /home/vmail
virtual_transport = virtual

# Configure disk quotas
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Lo sentimos, su buzon de correo esta lleno.
virtual_overquota_bounce = yes

We see that we have specified the ‘vmail’ user previously created (with UID and GID 5000 and login directory /home/vmail) as the effective user of all the virtual mail users to be created.

 Posted by at 11:18 am

  One Response to “How to install Postfixadmin to manage a Postfix mail server from a browser”

 Leave a Reply