Mar 022013
 

Postfix it’s a great mailserver, but it’s not the easiest of the beast to tame if you aren’t an expert system administrator and just want to setup a mail service for your server and domain, so today I’ll show you how to install and configure PostfixAdmin a web based interface used to manage mailboxes, virtual domains and aliases. It also features support for vacation/out-of-the-office messages.

This software is compatible with different databases and IMAP/POP3 server, in the following article I’ll use Mysql as database server, on a Centos 6 Linux server.



Short Description and features:

Postfix Admin is a Web Based Management tool created for Postfix. It is a PHP based application that handles Postfix Style Virtual Domains and Users that are stored in MySQL or PostgreSQL.

  • Web based administration for a virtual Postfix mail server
  • MySQL or PostgreSQL database support
  • Fetchmail support
  • Vacation / auto-reply support
  • Squirrelmail / Roundcube integration

First Step: Requirements

To run properly Postfix Admin need the following software available on your Linux server:

  • Postfix 2.0 or higher.
  • Apache 1.3.27 / Lighttpd 1.3.15 or higher.
  • PHP 5.1.2 or higher with modules for mysql.
  • MySQL (5.x recommended)

All these software are easily installable on Centos 6 via yum


Second Step : Postfix Admin Installation and setup

Download the latest versione of postfix Admin from sourceforge, in this moment the latest version it’s the 2.3.6.

Once downloaded the source package unpackage it on the document root of your Web Server, in this example my document root is /srv/posyfixadmin

cd /srv
tar -zxvf /tmp/postfixadmin-2.3.6.tar.gz
mv postfixadmin-2.3.6 postfixadmin

Setup a Database

With your chosen/preferred database server, you need to create a new database. A good name for this could be :

postfix

Most users will find using phpMyAdmin the easiest route to create a new database and user, or you can create MySQL user and databases quickly and easily by running mysql from the shell.

The syntax is shown below and the dollar sign is the command prompt:

$ mysql -uroot -p
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.1.67 Source distribution
 
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> CREATE DATABASE postfix;
Query OK, 1 row affected (0.00 sec)
 
mysql> CREATE USER 'postfix'@'localhost' IDENTIFIED BY 'yourpassword';
Query OK, 0 rows affected (0.00 sec)
 
mysql> GRANT ALL PRIVILEGES ON `postfix`.* TO 'postfix'@'localhost';
Query OK, 0 rows affected (0.00 sec)
 
mysql> exit
Bye
 
$

Now edit the config.inc.php file – or – create config.local.php and add your settings there.
The most important settings are those for your database server that should be similar to this one:

$CONF['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfix';
$CONF['database_password'] = 'yourpassword';
$CONF['database_name'] = 'postfix';

You must also change the line that says :

$CONF['configured'] = false;

to

$CONF['configured'] = true;

PostfixAdmin does not require write access to any files. You can therefore leave the files owned as root (or a.n.other user); as long as the web server user (e.g. www-data or apache) can read them, it will be fine.

Now open your browser at the url: http://yourservername.com/setup.php you should see a page like this one:

postfixadmin

It will make a basic checkup of your setup and will indicates if something is missing, at my first run I was missing php-mbstring and php-imap so I installed them with:

yum install php-mbstring php-imap

And restarted Apache, reloading the page I got an “Ok”
The setup.php script will attempt to create the database structure and you can specify a password (which you’ll need to use setup.php again in the future); when you submit the form, the hashed value, which you need to enter into config.inc.php is show with these instructions:

if you want to use the password you entered as setup password, edit config.inc.php and set
 
$CONF['setup_password'] = '1a05f571012e9f14c0f80f764d516f80:ec41add25de301101bac12649f929bbcbea8575e';

So change that line in the configuration file.
Now you can also create the postfixadmin administrator account with a form like this one:

postfixadmin-createadmin

And this end, you have successfully installed and configured Postfix Admin, you can visit your website and login with your admin account.

Postfix setup

This is the minimum configuration to get postfix working and good for testing. It will allow you to send unsecure email on port 25. Note, it is avisable to secure your email connection to at least protect your password which is discussed below, but first make sure your basic configuration is working.

Append this to /etc/postfix/main.cf:

virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
virtual_mailbox_base = /home/vmail
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_mailbox_domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
relay_domains = mysql:/etc/postfix/mysql_relay_domains.cf
smtpd_recipient_restrictions =
   permit_mynetworks,
   permit_sasl_authenticated,
   reject_non_fqdn_hostname,
   reject_non_fqdn_sender,
   reject_non_fqdn_recipient,
   reject_unauth_destination,
   reject_unauth_pipelining,
   reject_invalid_hostname
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous

Create the following files with the content:
/etc/postfix/mysql_virtual_mailbox_domains.cf

hosts = 127.0.0.1
user = postfix
password = my_passwd _2   #replace with the password you set above
dbname = postfixadmin
query = SELECT domain FROM domain WHERE domain='%s' and backupmx = 0 and active = 1

/etc/postfix/mysql_virtual_mailbox_maps.cf

hosts = 127.0.0.1
user = postfix
password = my_passwd_2  #replace with the password you set above
dbname = postfixadmin
query = SELECT maildir FROM mailbox WHERE username='%s' AND active = 1

/etc/postfix/mysql_virtual_alias_maps.cf

hosts = 127.0.0.1
user = postfix
password = my_passwd _2  #replace with the password you set above
dbname = postfixadmin
query = SELECT goto FROM alias WHERE address='%s' AND active = 1

/etc/postfix/mysql_relay_domains.cf

hosts = 127.0.0.1
user = postfix
password = my_passwd _2  #replace with the password you set above
dbname = postfixadmin
query = SELECT domain FROM domain WHERE domain='%s' and backupmx = 1

/etc/postfix/sasl/smtpd.conf

pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
auxprop_plugin: rimap

Update /etc/default/saslauthd with:

START=yes
MECHANISMS="rimap"
#imap server address
MECH_OPTIONS="localhost"
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"

Add postfix user to sasl group:

sudo adduser postfix sasl

Restart postfix

/etc/init.d/postfix restart

And now you’ll be able to create a new domain and mailboxes in it from the web with some simple forms:

postfixadmin-admin-create-domain

Admin – Create domain

postfixadmin-admin-create-mailbox

Admin – Create mailbox

postfixadmin-admin-create-mailbox

Admin – Create mailbox

postfixadmin-admin-domain-list

Admin – List domains

Popular Posts:

Flattr this!

  7 Responses to “Manage easyly Postfix with Postfixadmin”

  1. Hi, I don’t think that this is going to work.. You need to tell postfix to look domains/aliases which postfixadmin created in database, so you need to add virtual_alias_maps, virtual_mailbox_maps… in main.cf file. Correct me if I wrong..

    Cheers,

    Branko

  2. Appreciate the time you took to write this and all works well… with apache.

    Using lighttpd 1.4.31 however I ran into problems. Everything went well during the initial setup with postfixadmin but when I tried to login postfixadmin with the credentials I had created I got the 404 not found error.

    Changing the ‘postfix_admin_url = /postfixadmin didn’t help, it just refreshed the page asking for my user credentials again.

    Nothing major, I will just stick with apache but it would be great if I can get it working with lighttpd as it uses a significantly smaller resource footprint.

  3. Hi bro thanks for your post, I have a question, I´m running Postfix Admin 2.3.2 how can i upgrade with out overwrite all my data settings and db´s? thanks for your answer.

    Cheers.

  4. In your postfix settings you refer to the dbname “dbname = postfixadmin” but you’re dbsetup section talks about ‘postfix’ as the name

  5. how do i reset a certain user quota since their quota limit has been reached and they no longer receive mails

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*