Let's describe the mailbox quota setting, the ability to specify a quota, provided in postfixadmin by default, does not work and needs to be configured. In our case, we are configuring it on the Ubuntu\Debian mail server for the Dovecot service. This configuration allows you to set a mailbox limit so as not to exceed the size of the ssd disk of the vps server, since any corporate mailbox can be filled with heavy attachments, spam, which can lead to a significant consumption of disk space.
This guide assumes that you have already configured the mail server itself and that you need to configure mailbox quotas. More information about setting up a mail server can be found here:
You can also order a VPS with a pre-configured operating system and get a ready-made corporate mail server for the price of a VPS server.
1. Dovecot service setup
vi /etc/dovecot/conf.d/10-mail.conf
mail_plugins = $mail_plugins quota
Let's save the file.
vi /etc/dovecot/conf.d/20-imap.conf
protocol imap {
mail_plugins = $mail_plugins imap_quota
}
Let's save the file.
vi /etc/dovecot/conf.d/10-master.conf
service dict {
unix_listener dict { mode = 0660 user = vmail group = vmail } }
Let's save the file.
vi /etc/dovecot/conf.d/90-quota.conf
plugin {
quota = dict:User quota::proxy::quota
}
Let's save the file.
vi /etc/dovecot/dovecot.conf
dict {
quota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext
}
vi /etc/dovecot/dovecot-dict-sql.conf.ext
connect = host=localhost dbname=postfix user=postfix password=postfix123
map {
pattern = priv/quota/storage
table = quota2
username_field = username
value_field = bytes
}
map {
pattern = priv/quota/messages
table = quota2
username_field = username
value_field = messages
}
In the very first line, you must specify the existing data for connecting to the database, specified when setting up the mail server.
vi /etc/dovecot/dovecot-sql.conf.ext
user_query = SELECT CONCAT('/home/mail/',LCASE(domain
),'/',LCASE(maildir
)), 1024 AS uid, 1024 AS gid, CONCAT('*:bytes=', quota) AS quota_rule FROM mailbox WHERE username = '%u'
Let's save the file.
Let's restart the service:
systemctl restart dovecot
The operation of the quota can be checked in the console with the command by specifying an existing mailbox with a given quota in postfixadmin:
doveadm quota get -u user@domain.tld
2. Set up quota exceeding notifications
vi /etc/dovecot/conf.d/90-quota.conf
Add lines to the config:
plugin {
quota_warning = storage=95%% quota-warning 95 %u
quota_warning2 = storage=80%% quota-warning 80 %u
}
In the same file, we bring the service quota-warning section to the form:
service quota-warning
executable = script /usr/local/bin/quota-warning.sh
user = dovecot
unix_listener quota-warning {
user = vmail
}
}
Let's create the script for sending notifications:
vi /usr/local/bin/quota-warning.sh
#!/bin/sh PERCENT=$1 USER=$2 cat << EOF | /usr/lib/dovecot/dovecot-lda -d $USER -o "plugin/quota=maildir:User quota:noenforcing" From: postmaster@domain.tld Subject: quota warning
Your mailbox is now $PERCENT% full.
EOF
Let's save the file. Change the email address from which the sending will take place in it to your own. Assign execution rights and apply the settings:
chmod +x /usr/local/bin/quota-warning.sh
systemctl restart dovecot
Let's check the script in the console:
/usr/local/bin/quota-warning.sh 85 user@domain.tld
Change the mailbox to an existing one, a letter should come to it.
The quota setting is complete, if an email with an attachment larger than the mailbox itself is sent to the mailbox, the email will not be delivered, and the sender will receive a message that the mailbox is full. Now the quotas set in postfixadmin are configured and working.