Your mail server doesn't have infinite space. Especially if you use IMAP then users appreciate the comfort of leaving their emails on the server. And there are even IMAP users who are not aware of emails that are just marked for deletion but are still occupying space. So unless you have very few or just highly disciplined users you may want to limit the space a user can occupy. Dovecot can store the size of a user's mailbox and the number of mails therein along with the virtual folder.
Enabling the quota plugin in Dovecot
There are three locations in the /etc/dovecot/dovecot.conf file where you need to enable the quota plugin (taken from the Dovecot documentation):
protocol imap {
mail_plugins = quota imap_quota
}
protocol pop3 {
mail_plugins = quota
}
protocol lda {
mail_plugins = quota
}
Setting global quota
The simplest case is a general quota limit for all users. Say you grant every user 1 GB of space with no more than 1000 emails. This would be the configuration in your /etc/dovecot/dovecot.conf file:
plugin {
quota = maildir:storage=1000000:messages=1000
}
Keep in mind that the storage parameter refers to KB. You can even omit the messages parameter if you don't intend to limit the number of messages.
Setting per-user quota
If you have certain users who have different quotas from your global quota setting then you can store the quota settings in your virtual_users table. Use this SQL statement to add two columns to the virtual_users table:
mysql>
ALTER TABLE `virtual_users` ADD `quota_kb` INT NOT NULL,
ADD `quota_messages` INT NOT NULL ;
And you will have to enable the user_query in your /etc/dovecot/dovecot-sql.conf. Throughout this tutorial it was suggested you use the "userdb static" approach in your /etc/dovecot/dovecot.conf. But this assumes that all users have equal settings. So in this per-user quota situation you will need to disable "userdb static" again and enable "userdb sql" to make Dovecot make an extra query to fetch the user's data from the database:
#userdb static {
# args = uid=5000 gid=5000 home=/var/vmail/%d/%n allow_all_users=yes
#
userdb sql {
args = /etc/dovecot/dovecot-sql.conf
}
And in your /etc/dovecot/dovecot-sql.conf add this line:
user_query = SELECT CONCAT('/var/vmail/',CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1))) AS home, 5000 AS uid, 5000 AS gid, CONCAT('maildir:storage=',quota_kb,':messages=',quota_messages) AS quota FROM virtual_users WHERE email='%u';
This query may look a bit weird but it does the same as the above
args = uid=5000 gid=5000 home=/var/vmail/%d/%n allow_all_users=yes
line and in addition gets the quota_kb and quota_messages information.
What happens if a user is over quota
Quotas in Dovecot aren't especially user-friendly. For example the recipient does not get a warning at a soft quota limit. Just the sender gets a bounce email with the subject reading "Automatically rejected mail" saying "Your message to <john@example.com> was automatically rejected: Quota exceeded"
16 Comments
What happens if a user is over quota
Submitted by Anonymous (not verified) on
http://wiki.dovecot.org/Quota/1.1?highlight=quota
Debian Lenny has the version
Submitted by Christoph Haas on
Debian Lenny has the version 1.0.15 of Dovecot. The feature you are quoting is not supported before version 1.1. So this wouldn't work unless the Debian package has patches for that functionality. And from a quick glance over the source package it doesn't.
Hi Christoph Hass, you're wrong
Submitted by Anonymous (not verified) on
>Hi Christoph, you're wrong. Take a look on the 1.0 dovecot quota page http://wiki.dovecot.org/Quota/1.0?highlight=quota Best Regards, Jhanssen Oliveira.
What's your point?
Submitted by Christoph Haas on
What's your point?
maildir
Submitted by Anonymous (not verified) on
fi you use a thunderbird Pluginn called "display quota" and only a few email
users on your server - use
with "maildir" the level of my mailbox isn't displayed correct. It is only displaying the level in trash.
If anybody get another option to do this - plz tell. High CPU load isn't good
1.2 compatability mod
Submitted by Anonymous (not verified) on
Add to dovecot.conf
mail_uid = vmail mail_gid = vmail change to the following: mechanisms = plain login digest-md5 cram-md5 #passdb passwd-file { # File contains a list of usernames, one per line #args = /etc/dovecot.deny #}passdb sql { args = /etc/dovecot/dovecot-sql.conf }#userdb passwd { # [blocking=yes] - By default the lookups are done in the main dovecot-auth # process. This setting causes the lookups to be done in auth worker # proceses. Useful with remote NSS lookups that may block. # NOTE: Be sure to use this setting with nss_ldap or users might get # logged in as each others! #args = #} #userdb passwd-file { # Path for passwd-file #args #}#userdb static { # Template for the fields. Can return anything a userdb could normally # return. For example: # # args = uid=5000 gid=5000 home=/var/mail/%d/%n allow_all_users=yes # # If you use deliver, it needs to look up users only from the userdb. This # of course doesn't work with static because there is no list of users. # Normally static userdb handles this by doing a passdb lookup. This works # with most passdbs, with PAM being the most notable exception. If you do # the user verification another way, you can add allow_all_users=yes to # the args in which case the passdb lookup is skipped. # #args = #} userdb sql { # Path for SQL configuration file args = /etc/dovecot/dovecot-sql.conf }protocol lda { log_path = /var/log/dovecot.log auth_socket_path = /var/run/dovecot/auth-master postmaster_address = postmaster@domain.com mail_plugins = quota sieve global_script_path = /var/mail/globalsieverc } plugin {Now for dovecot-sql.conf: driver = mysql connect = host=127.0.0.1 dbname=provider user=provider password=<password> user_query = SELECT CONCAT('/var/mail/',CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1))) AS home, 5000 AS uid, 5000 AS gid, CONCAT('*:bytes=',quota_kb) AS quota_rule FROM virtual_users WHERE email='%u'; default_pass_scheme = plain login crypt digest-md5 cram-md5Details....
Submitted by Anonymous (not verified) on
Edit the quota_kb to allow varchar and insert the limits like 500K, 100M, 1G etc.
Details......
Submitted by Anonymous (not verified) on
password_query = SELECT email as user, password, 5000 AS userdb_uid, 5000 AS userdb_gid, CONCAT('*:bytes=',quota_kb) AS userdb_quota_rule FROM virtual_users WHERE email='%u' ;
To finish the deal
Does not work for me
Submitted by Anonymous (not verified) on
I also had the idea to handle it that way, but it just won't work for me.
I always get this error:
Jul 14 14:13:32 MY_HOST dovecot: IMAP(sebastian.buettner@MY_DOMAIN): maildir quota: Unknown setting: User quota
Is there any point I could start solving this problem?
Thanks and cheers,
Sebastian
Bravo!
Submitted by Anonymous (not verified) on
Great job! Really great!
I'm interested in finding out (if you have the time, that is) how to put per-domain quota.
That feature would really make my day! :)
Best wishes!
Dovecot 1.1
Submitted by Anonymous (not verified) on
Thanks Christoph. I've made it this far without a problem. The best Linux Tut I've seen by far!
I followed the instructions above, restarted dovecot and bang, it crashed. Checked the version to find that it is
1.1.11 and not 1.0 as you indicated earlier. It must be a new(ish) update as I only installed Lenny about 10 days
ago.
I'm having a go at the instructions at http://wiki.dovecot.org/Quota/1.1 but a simplified version in your inimitable
style would really help.
Regards
Grant
Dovecot 1.1
Submitted by Anonymous (not verified) on
Oh boy, my bad.
I started by installing Lenny but couldn't get gnome to work with my nvidia card so ended up installing
Ubuntu Karmic.
The tutorial was working so well I forgot :(
Quota exceeded with recipient's address shown
Submitted by Anonymous (not verified) on
Great tutorial. I'm a newbie. I followed your tutorial on debian etch and am using dovecot 1.0.rc15. Everything works fine except for quota. When a mailbox quota exceeds, all the sender gets is this bounce e-mail:
"Your message was automatically rejected by Dovecot Mail Delivery Agent.
The following reason was given:
Quota exceeded"
Can the recipient e-mail address be added to the above message without upgrading dovecot?
I've seen something called "backports" when googling. If I really have to upgrade dovecot, is it the way to go? And will the new dovecot recognize the existing 'dovecot.conf' and others?
problem with schema mysql to upgrade dovecot 1.2
Submitted by Anonymous (not verified) on
Hi ,
I have a problem with upgrade dovecot 1.2 . Dovecot 1.2 use a new schema for mysql quota . i create a new table as here
CREATE TABLE quota (
In my file dovecot-sql.conf i add this line
user_query = SELECT [/var/vmail/] AS home, 5000 AS uid, 5000 AS gid, CONCAT('*:bytes=', CAST(quota AS CHAR)) AS quota_rule FROM mailbox WHERE username = '%u';
but after reload dovecot the quota don't work for my all account .
yet i use to avoid the problem .
In my dovecot.conf
Per-user quota dovecot-1.2
Submitted by Anonymous (not verified) on
That's very easy:
user_query = SELECT CONCAT('/var/vmail/',CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1)),'/Maildir') AS home, 5000 AS uid, 5000 AS gid, CONCAT('*:storage=',quota_kb) AS quota_rule FROM virtual_users WHERE email='%u';
What I still didn't found is how to fallback to the default quota when no quota is specified (example: quota_kb=0).
quota in squeeze
Submitted by Anonymous (not verified) on
hi,
does the global quota settings works also for the new tutorial on squeeze?