Postfix
For MySQL users, define the following map files on your server (it should work with
postfix versions >= 2.2):
/etc/postfix/sql-domains.cf:
user = <user>
password = <password>
dbname = <database>
hosts = 127.0.0.1
query = SELECT name FROM admin_domain WHERE name='%s' AND enabled=1
/etc/postfix/sql-domain-aliases.cf:
user = <user>
password = <password>
dbname = <database>
hosts = 127.0.0.1
query = SELECT t2.name FROM admin_domainalias AS t1, admin_domain AS t2 WHERE t1.target_id=t2.id AND t1.enabled=1 AND t2.enabled=1 AND t1.name='%s'
/etc/postfix/sql-mailboxes.cf:
user = <user>
password = <password>
dbname = <database>
hosts = 127.0.0.1
query = SELECT concat(t2.name, '/', t1.path, (SELECT value FROM lib_parameter WHERE name='admin.MAILDIR_ROOT', '/') FROM admin_mailbox AS t1, admin_domain AS t2 WHERE t1.enabled=1 AND t1.domain_id=t2.id AND t1.address='%u' AND t2.enabled=1 AND t2.name='%d'
/etc/postfix/sql-aliases.cf:
user = <user>
password = <password>
dbname = <database>
hosts = 127.0.0.1
query = (SELECT concat(t1.address, '@', t2.name) FROM admin_mailbox t1, admin_domain t2 WHERE t1.id IN (SELECT t3.mailbox_id FROM admin_alias t1, admin_domain t2, admin_alias_mboxes t3 WHERE t1.enabled='1' AND t1.address='%u' AND t1.domain_id=t2.id AND t2.name='%d' AND t3.alias_id=t1.id) AND t1.domain_id=t2.id) UNION (SELECT t1.extmboxes FROM admin_alias AS t1, admin_domain AS t2 WHERE t1.enabled='1' AND t1.extmboxes<>'' AND t1.address='%u' AND t1.domain_id=t2.id AND t2.name="%d" AND t2.enabled='1')
/etc/postfix/sql-forwards.cf:
user = <user>
password = <password>
dbname = <database>
hosts = 127.0.0.1
query = SELECT t1.extmboxes FROM admin_alias AS t1, admin_domain AS t2 WHERE t1.enabled=1 AND t1.address='%u' AND t1.domain_id=t2.id AND t2.name="%d" AND t2.enabled=1
/etc/postfix/sql-domain-aliases-mailboxes.cf:
user = <user>
password = <password>
dbname = <database>
hosts = 127.0.0.1
query = SELECT concat(t2.address, '@', t3.name) FROM admin_domainalias AS t1, admin_mailbox AS t2, admin_domain AS t3 WHERE t1.target_id=t2.domain_id AND t2.domain_id=t3.id AND t1.name='%d' AND t2.address='%u'
Then, use the following configuration in the /etc/postfix/main.cf file
(this is just one possible configuration):
# Stuff before
mailbox_transport = virtual
maildrop_destination_recipient_limit = 1
virtual_minimum_uid = <vmail user id>
virtual_gid_maps = static:<vmail group id>
virtual_uid_maps = static:<vmail user id>
virtual_mailbox_base = /var/vmail
relay_domains =
virtual_mailbox_domains = mysql:/etc/postfix/sql-domains.cf
virtual_alias_domains = mysql:/etc/postfix/sql-domain-aliases.cf
virtual_mailbox_maps = mysql:/etc/postfix/sql-mailboxes.cf
virtual_alias_maps = mysql:/etc/postfix/sql-aliases.cf,
mysql:/etc/postfix/sql-domain-aliases-mailboxes.cf
# Stuff after
Note
Modoboa supports both maildir and mbox formats. You can specify
which format to use by modifying the MAILBOX_TYPE parameter available
in the admin panel.
Optional : ‘catchall’ aliases
Modoboa supports ‘catchall’ aliases creation. In the case you would
like to use this feature, you’ll need to add specific queries to
postfix configuration.
First, create the following new maps (MySQL users):
/etc/postfix/sql-email2email.cf:
user = <user>
password = <password>
dbname = <database>
hosts = 127.0.0.1
query = SELECT concat(t1.address, '@', t2.name) FROM admin_mailbox AS t1, admin_domain AS t2 WHERE t1.domain_id=t2.id AND t1.address='%u' AND t2.name='%d'
/etc/postfix/sql-catchall-aliases.cf:
user = <user>
password = <password>
dbname = <database>
hosts = 127.0.0.1
query = (SELECT concat(t1.address, '@', t2.name) FROM admin_mailbox t1, admin_domain t2 WHERE t1.id IN (SELECT t3.mailbox_id FROM admin_alias t1, admin_domain t2, admin_alias_mboxes t3 WHERE t1.enabled='1' AND t1.address='*' AND t1.domain_id=t2.id AND t2.name='%d' AND t3.alias_id=t1.id) AND t1.domain_id=t2.id) UNION (SELECT t1.extmboxes FROM admin_alias AS t1, admin_domain AS t2 WHERE t1.enabled='1' AND t1.extmboxes<>'' AND t1.address='*' AND t1.domain_id=t2.id AND t2.name="%d" AND t2.enabled='1')
Once done, edit the main.cf configuration file and add the new maps
to the virtual_alias_maps parameter like this:
virtual_alias_maps = mysql:/etc/postfix/sql-aliases.cf,
mysql:/etc/postfix/sql-forwards.cf,
mysql:/etc/postfix/sql-domain-aliases-mailboxes.cf,
mysql:/etc/postfix/sql-email2email.cf, # new
mysql:/etc/postfix/sql-catchall-aliases.cf # new
Reload postfix.
Optional: using Dovecot’s LDA
If you are using Dovecot in your environnement, I recommend to use
its LDA. Doing so, you’ll will be able to use extra functionalities
such as sieve filters and more.
First, edit the /etc/postfix/main.cf file and define (or modify if
they already exist) the following parameters:
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1
Then, edit the /etc/postfix/master.cf file and add the following
definition at the end:
dovecot unix - n n - - pipe
flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${recipient}
If you have followed the Postfix section to install your
environnement, you need to modify the SQL query corresponding to the
virtual_mailbox_maps parameter. Edit the
/etc/postfix/maps/sql-mailboxes.cf and modify the query
parameter as follow:
query = SELECT concat(t2.name, '/', t1.path) FROM admin_mailbox AS t1, admin_domain AS t2 WHERE t1.enabled=1 AND t1.domain_id=t2.id AND t1.address='%u' AND t2.enabled=1 AND t2.name='%d'
Restart Postfix.
Dovecot
If you are using the maildir format to store mailboxes, add the
following line into Dovecot’s main config file
(/etc/dovecot/dovecot.conf):
mail_location = maildir:<path_to_mailboxes>/%h/.maildir
The .maildir part is the previous example must match the value of
the MAILDIR_ROOT parameter. See Default configuration.
If you are using the mbox format, add the following:
mail_location = mbox:<path_to_mailboxes>/%h/:INBOX=<path_to_mailboxes>/%h/Inbox
To make the authentication work, edit dovecot.conf and add the
following content inside:
auth default {
# ... stuff before
passdb sql {
# Path for SQL configuration file, see /etc/dovecot/dovecot-sql.conf for
# example
args = /etc/dovecot/dovecot-sql.conf
}
userdb sql {
# Path for SQL configuration file
args = /etc/dovecot/dovecot-sql.conf
}
# ... stuff after
}
Make sure to activate only one backend (per type) inside your configuration
(just comment the other ones).
For MySQL users, edit your /etc/dovecot/dovecot-sql.conf and modify following lines:
driver = mysql
connect = host=<mysqld socket> dbname=<database> user=<user> password=<password>
default_pass_scheme = CRYPT
password_query = SELECT concat(t1.address, '@', t2.name) AS user, password FROM admin_mailbox AS t1, admin_domain AS t2 WHERE t1.domain_id=t2.id AND t1.address='%n' AND t2.name='%d'
user_query = SELECT concat(t2.name, '/', t1.path) AS home, uid, gid FROM admin_mailbox AS t1, admin_domain AS t2 WHERE t1.domain_id=t2.id AND t1.address='%n' AND t2.name='%d'
Enable quotas support
Put the following lines inside the dovecot.conf file:
protocol imap {
mail_plugins = quota imap_quota
}
Before continuing, you need to know which quota backend must be used
(function of mailboxes format):
- mbox : backend=dirsize,
- maildir : backend=maildir.
If you use version prior to 1.1, add also the following configuration:
plugin {
# 10 MB default quota limit
quota = <backend>:storage=10240
}
For MySQL users, modify the above query inside dovecot-sql.conf as
follow to activate per-user quotas:
user_query = SELECT concat(t2.name, '/', t1.path) AS home, uid, gid, concat('<backend>:storage=', t1.quota / 1024) AS quota FROM admin_mailbox AS t1, admin_domain AS t2 WHERE t1.domain_id=t2.id AND t1.address='%n' AND t2.name='%d'
For version >= 1.1, put the following configuration inside the dovecot.conf file:
plugin {
# Default 10M storage limit with an extra 5M limit when saving to Trash.
quota = <backend>:User quota
quota_rule = *:storage=10M
quota_rule2 = Trash:storage=5M
}
For MySQL users, modify the above query inside dovecot-sql.conf to
activate per-user quotas:
user_query = SELECT concat(t2.name, '/', t1.path) AS home, uid, gid, concat('*:storage=', t1.quota, 'M') AS quota_rule FROM admin_mailbox AS t1, admin_domain AS t2 WHERE t1.domain_id=t2.id AND t1.address='%n' AND t2.name='%d'
Enable ManageSieve/Sieve support
Note
The following configuration example should work with versions
1.X. For versions >= 2, please refer to Dovecot’s wiki.
Edit the /etc/dovecot/dovecot.conf file and make the following
modifications:
Add managesieve to the protocols variable:
protocols = imap imaps managesieve
Uncomment the managesieve section:
protocol managesieve {
# ...
}
Configure the lda protocol as follow:
protocol lda {
postmaster_address = postmaster@<your domain>
mail_plugins = sieve # + your other plugins
# ...
}
In the plugin section, uncomment the following content:
plugin {
# stuff before
# Location of the active script. When ManageSieve is used this is actually
# a symlink pointing to the active script in the sieve storage directory.
sieve=~/.dovecot.sieve
#
# The path to the directory where the personal Sieve scripts are stored. For
# ManageSieve this is where the uploaded scripts are stored.
sieve_dir=~/sieve
}
Restart Dovecot.
Note
If you’re using Postfix as MTA, you will have to use Dovecot‘s
local delivery agent otherwise your emails won’t get filtered. See
Optional: using Dovecot’s LDA to get information on how to activate this.