Postcot + Postfix + Dovecot + Postgresql

postcot manages an email-address database for a generic email server based on virtual users

it requires:
- postgresql or mysql database
- postfix smtp server
- dovecot imap/pop3 server, best with dovecot with LDA
- php5 with pdo

1. create database

    su - postgres
    psql template1
    

2. create database table

    PGPASSWORD=postk012 psql -h localhost -U postcot postcotdb
    

3. configure apache and php

    apt-get install libapache2-mod-php5 php5-pgsql php5-pdo
    vi /etc/apache2/sites-available/postcot.inc
    
    vi /etc/apache2/sites-available/example
    

4. configure postcot and run

    vi pc-config.inc.php
    
    open browser to
	http://postcot.lan/postcot
    login as
	postmaster@example.it / password
    

5. configure postfix

create vmail system user as owner of vmail directory (mailbox repository /home/vmail)
    groupadd -g 5000 vmail
    useradd -m -u 5000 -g 5000 -s /bin/false vmail
    
install postfix in bundle with dovecot (ubuntu)
    apt-get install dovecot-postfix
    apt-get install postfix-pgsql
    cd /etc/postfix
    
select all active domains
    vi vhosts-sql.cf
    
- pgsql: comment #host for fast unix socket
- mysql: use 127.0.0.1 to avoid "postfix/trivial-rewrite[26321]: fatal: mysql:/etc/postfix/valias-sql.cf(0,lock|fold_fix): table lookup problem"

select all active email addresses
    vi vmailbox-sql.cf
    
- %s addr %u user %d domain
- select 1 if transport is dovecot lda

select all active email aliases
    vi valias-sql.cf
    
configure postfix virtual users
    vi main.cf
    
- 5000 is vmail uid
- reject_unauth_destination reject unknown email recipient

enable dovecot local delivery (support quota and sieve... vacation)
    vi master.cf
    

6. configure dovecot

    apt-get install dovecot-pgsql
    cd /etc/dovecot
    
select all mailbox and aliases
    vi dovecot-sql.conf.ext
    
- see http://wiki2.dovecot.org/AuthDatabase/SQL
    vi conf.d/auth-sql.conf.ext
    
    vi conf.d/01-mail-stack-delivery.conf
    
    vi conf.d/10-auth.conf
    
test configuration:
    dovecot -n
    

7. configure system

www-data (user group) can run disk usage command (du)
    visudo
    

8. end