Postfix Virtual Hosting With LDAP Backend And With Dovecot As IMAP/POP3 Server On Ubuntu Intrepid Ibex Server 8.10 - Page 4

Step 5: Install And Configure Dovecot

apt-get install dovecot-imapd dovecot-pop3d

This will install dovecot and all necessary files and also create the standard ssl certificates for IMAPs and POP3s.

Now we back up the original configuration file for safe keeping.

mv /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf.bck
mv /etc/dovecot/dovecot-ldap.conf /etc/dovecot/dovecot-ldap.conf.bck

Next you can create new configuration files with the examples provided below.

vi /etc/dovecot/dovecot.conf

auth_verbose = yes
mail_debug = no

base_dir = /var/run/dovecot/
protocols = imap imaps pop3 pop3s
protocol lda {
  mail_plugins = quota
  postmaster_address = postmaster@example.tld
  auth_socket_path = /var/run/dovecot/auth-master
listen = *
shutdown_clients = yes
log_timestamp = "%b %d %H:%M:%S "
syslog_facility = mail
disable_plaintext_auth = no
ssl_disable = no
ssl_cert_file = /etc/ssl/certs/mail.example.tld.pem
ssl_key_file = /etc/ssl/certs/mail.example.tld.pem
login_chroot = yes
login_user = postfix
login_process_per_connection = yes
login_processes_count = 2
login_max_processes_count = 128
login_max_connections = 256
login_greeting = Welcome to Dovecot eMail Server.
login_log_format_elements = user=<%u> method=%m rip=%r lip=%l %c
login_log_format = %$: %s
#default_mail_env = maildir:/home/vmail/%d/%u
mail_location = maildir:/home/vmail/%d/%u
first_valid_uid = 108 # REMEBER THIS MUST BE CHANGED TO YOUR UID FOR "postfix" FROM /etc/passwd
mail_uid = 1000
mail_gid = 1000
pop3_uidl_format = %08Xu%08Xv
auth default {
    mechanisms = PLAIN LOGIN
    passdb ldap {
        args = /etc/dovecot/dovecot-ldap.conf
    userdb ldap {
        args = /etc/dovecot/dovecot-ldap.conf
socket listen {
                master {
                        path = /var/run/dovecot/auth-master
                                mode = 0600
                        user = vmail
                        group = vmail
                client {
                        path = /var/spool/postfix/private/auth
                        mode = 0660
                        user = postfix
                        group = postfix
        user = vmail

vi /etc/dovecot/dovecot-ldap.conf

hosts = localhost
auth_bind = yes
auth_bind_userdn = mail=%u,vd=%d,o=hosting,dc=example,dc=tld
ldap_version = 3
base = o=hosting,dc=example,dc=tld
dn = cn=admin,dc=example,dc=tls
dnpass = your openldap password
deref = never
scope = subtree
user_attrs = quota=quota=maildir:storage
user_filter = (&(objectClass=VirtualMailAccount)(accountActive=TRUE)(mail=%u))
pass_attrs = mail,userPassword
pass_filter = (&(objectClass=VirtualMailAccount)(accountActive=TRUE)(mail=%u))
default_pass_scheme = MD5

Note: Remember to change example.tld to your own domain.tld (see assumptions).

Quota support is enabled, but no quota warnings are issued. This can be done by adding the following to your dovecot.conf:

plugin {
  quota_warning = storage=95%% /usr/local/bin/ 95
  quota_warning2 = storage=80%% /usr/local/bin/ 80

Now we need to create the

vi /usr/local/bin/

And paste the following into it:

cat << EOF | /usr/local/libexec/dovecot/deliver -d $USER
Subject: quota warning

Your mailbox is now $PERCENT% full.

Now me make the script executable:

chmod +x /usr/local/bin/

This concludes the Dovecot coonfiguration.

Share this page:

13 Comment(s)

Add comment


From: ronw at: 2009-02-11 15:30:43

When I run the ldapmodify command with the acl-del.ldif file I get the following message:

ldapmodify: wrong attributeType at line 3, entry "olcDatabase={1}hdb,cn=config"

What did I miss?

From: at: 2009-03-22 23:23:48

Hi, here is a thread to talk about the ACL problem:

From: MyTer at: 2009-02-06 14:00:12

Hi hoihtah

I got the same outcome, but I moved ldif_out to be under


and also placed schema.convert there,

that did the trick!


From: at: 2009-01-24 19:28:14

Beautifull, simply outstanding. Thank you very much.


From: at: 2009-01-26 23:31:50

I'm getting no such file or directory error after

 cp phamm-0.5.15/schema/phamm.schema .

 which directory should I be in when i run that command?

From: Pietro at: 2009-03-02 09:12:37

Argh... the same to me...

Conf: ubuntu server8.10 just apt-get updated and upgraded...

From: ww at: 2009-02-26 02:28:01

I am encountering the same error as ronw:

When I run the ldapmodify command with the acl-del.ldif file I get the following message:

ldapmodify: wrong attributeType at line 3, entry "olcDatabase={1}hdb,cn=config"

What did I miss?

From: Anonymous at: 2009-05-21 19:38:20

same here ... don;t know how to get through it :( ...

From: Alex at: 2009-07-30 19:18:34

To fix this issue, simply delete the lines manually from the olcDatabase={1}hdb.ldif file...

vi /etc/ldap/slapd.d/cn\=config/olcDatabase\=\{1\}hdb.ldif

From: P. Larsen at: 2009-09-11 00:15:02

Thanks for your guide - it's been helpful getting me to understand phamm better.

I wish you could clarify a few areas of why you choose to do what you did. First of all, how/where do you bind phamm into the mail delivery process so anti-virus and spam filters can be applied or not, depending on the user's configuration option?

What's the advantage of using dovecot as a delivery method?

From: rich at: 2009-04-30 20:38:42

when editing the there seems to be a typo that really had me stuck for a while and it would like to point it out. Notice at the end of the string where is says {recipient)

it should read {recipient} they both should have curly braces not a parenthesis at the end

This is the right string below

dovecot   unix  -       n       n       -       -       pipe
     flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${recipient}

From: rich at: 2009-04-30 20:49:40

If you want your mail to end up in /home/vmail/domains so the full path of an email mailbox looks like this /home/vmail/domains/example.tld/bob@example.tld, which phamm and ldap is expecting it to be, you would need to change.

mail_location = maildir:/home/vmail/%d/%u


mail_location = maildir:/home/vmail/domains/%d/%u



From: Anonymous at: 2009-03-09 14:20:13

hi there, great work on this howto.

there's some work that isn't entirely explicit, which is mostly fine, except for security holes.  since you configure various things to use the rootdn, those configuration files should be unreadable.

# chmod o-rwx /etc/postfix/ (readable by all by default)

# chmod o-rwx /etc/dovecot/dovecot-ldap.conf (secure by default in ubuntu intrepid, but good practice to check)

# chmod o-rwx /etc/gnarwl.cfg (readable by all by default)