There is a new version of this tutorial available for Ubuntu 18.04 (Bionic Beaver).

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 = [email protected]
  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/quota-warning.sh 95
  quota_warning2 = storage=80%% /usr/local/bin/quota-warning.sh 80
}

Now we need to create the quota-warning.sh:

vi /usr/local/bin/quota-warning.sh

And paste the following into it:

#!/bin/bash
PERCENT=$1
cat << EOF | /usr/local/libexec/dovecot/deliver -d $USER
From: [email protected]
Subject: quota warning

Your mailbox is now $PERCENT% full.
EOF

Now me make the script executable:

chmod +x /usr/local/bin/quota-warning.sh

This concludes the Dovecot coonfiguration.

Share this page:

1 Comment(s)