Postfix does not support mailbox quota. But thanks to Anderson Nadal’s Postfix Virtual Delivery Agent (VDA) patches, it can. To use the Postfix VDA requires two things, first Postfix must be built with the VDA patches and second, virtual user accounts must be used. You can get the Postfix RPM with VDA patches here.
If you have installed Postfix with VDA and your Postfix is configured for virtual user accounts, you can proceed to Configure Postfix VDA section.
Create the Virtual Mail User Account
1. Create a new user, we will call it vmail. Change the Login Shell to /sbin/nologin, this user account should not be used for logging in. Learn how to use the User Manager application here.
3. Click the Groups tab and now note down the Group ID of vmail. We’ll be needing all of them later.
Configure Postfix for Virtual User Accounts
mydestination = $myhostname, localhost.$mydomain, localhost
and add the lines below
virtual_mailbox_domains = $mydomain
virtual_mailbox_base = /home/vmail/
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
virtual_uid_maps = static:501
virtual_gid_maps = static:501
virtual_mailbox_base, virtual_uid_maps and virtual_gid_maps should contain the home directory, user id and group id of vmail respectively.
2. Create the file /etc/postfix/vmailbox containing the mapping from an email address to a mailbox path relative to virtual_mailbox_base. See the example below.
johndoe@acme.local johndoe/Maildir/
janedoe@acme.local janedoe/Maildir/
You can generate the vmailbox file automatically by executing
getent passwd | grep /bin/bash | sed 's/\([^:]*\):.*/\1@acme.local \1\/Maildir\//' > /etc/postfix/vmailbox
After creating this file, execute postmap /etc/postfix/vmailbox. This will generate /etc/postfix/vmailbox.db, the actual file that will be used for the lookup.
3. Restart the Postfix or MailScanner service if you have installed MailScanner. Learn how to start and stop services here.
4. Try sending an email. See Test Postfix using Telnet. New mails should now be stored under the path specified in virtual_mailbox_base.
Configure Dovecot Virtual User Accounts
1. Edit the file /etc/dovecot.conf and change the value of the following keys below
userdb static {
args = uid=501 gid=501 home=/home/vmail/%u
}
uid, gid and home should contain the user id, group id and home directory respectively of the vmail user account.
You should also comment out the userdb passwd section, otherwise it will override the values in userdb static above.
3. Test Dovecot using Telnet. You should be able to read the recently sent mail which was stored in a new location.
Configure Postfix VDA
1. Edit the postfix configuration file /etc/postfix/main.cf and add the lines below
virtual_mailbox_limit_override = yes
virtual_mailbox_limit_maps = hash:/etc/postfix/vquota
2. Create the file /etc/postfix/vquota containing the mapping from an email address to the maximum mailbox quota in bytes. If you wish to be exact, 1KB equals 1024 bytes while 1MB equals 1024KB or 1048576 bytes.
johndoe@acme.local 10485760
janedoe@acme.local 2097152
John Doe got a 10MB quota while Jane Doe got 2MB.
After creating this file, execute postmap /etc/postfix/vquota. This will generate /etc/postfix/vquota.db, the actual file that will be used for the lookup.
If you use Active Directory as your Postfix virtual user accounts source, you can use the maxStorage attribute instead to store the quota. Just copy your ldap-users.cf configuration and save it as ldap-quota.cf. Next change samaccountname to maxstorage in the result_attribute line and remove the result_format line. In your main.cf, use ldap:/etc/postfix/ldap-quota.cf as your virtual_mailbox_limit_maps. In Windows, you can use ADSI Edit to access and modify the value of maxStorage.
3. Restart the Postfix or MailScanner service if you have installed MailScanner. Learn how to start and stop services here.
REFERENCE