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 Kamic Koala 9.10 - Page 3

Step 4: Install And Configure Dovecot

aptitude 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 imap {
        mail_plugins = quota imap_quota
        imap_client_workarounds = outlook-idle

}
protocol pop3 {
        mail_plugins = quota
        pop3_no_flag_updates = yes
        pop3_reuse_xuidl = no
        pop3_lock_session = no
        pop3_client_workarounds = outlook-no-nuls oe-ns-eoh
}
protocol lda {
  mail_plugins = quota
  postmaster_address = [email protected]
  auth_socket_path = /var/run/dovecot/auth-master
  }
plugin {
        quota = maildir
        quota_rule = Trash:storage=10%%
        quota_rule2 = Spam:storage=10%%
        quota_warning = storage=95%%/home/vmail/bin/quota-warning.sh 95
        quota_warning2 = storage=80%% /home/vmail/bin/quota-warning.sh 80
}
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 #==> Change this and below to the neame you want
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=phamm,o=hosting,dc=example,dc=tls #The readonly user
dnpass = the readonly 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
user_attrs = quota=quota=maildir:storage=%$B

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 with a script file that issues the quota warnings.

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 -c /etc/dovecot/dovecot-nowarning.conf
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

The dovecot-nowarning.conf is a copy from your dovecot.conf file from which the % warning lines are removed.

So we copy the dovecot.conf file:

cp /etc/dovecot/dovecto.conf /etc/dovecto/dovecot-nowarning.conf

We edit this files and remove the lines below.

nano /etc/dovecto/dovecot-nowarning.conf
quota_warning = storage=95%%/home/vmail/bin/quota-warning.sh 95
quota_warning2 = storage=80%% /home/vmail/bin/quota-warning.sh 80

The lines below specify the amount of space (from the quota) that is assigned to the Trash and Spam folder.

quota_rule = Trash:storage=10%%
quota_rule2 = Spam:storage=10%%

This configuration uses 10 of the total quota for the mailbox respectively for the Trash and Spam folder. So with a quota of 100Mbyte a user is limited to 80Mbyte for emails, 10Mbyte for the Trash folder and 10Mbyte for the Spam folder.

This concludes the Dovecot configuration.

Share this page:

1 Comment(s)