This is an old revision of the document!
This is an improved version from the original article in ispcp (http://isp-control.net/documentation/howto:mail:replace_courier_with_dovecot) All the parts related to the default install where removed since imscp already takes care of that, and it's focused to add the functionality that is available only on dovecot (instead of courier). The required dovecot version is now 1.2 (squeeze's default)
Please report any bugs/hints/whatever in the following board thread: http://forum.i-mscp.net/showthread.php?tid=61
NOTE: There are currently no means to configure the quota for imscp other than fiddling with the database. The functionality from http://www.isp-control.net/forum/thread-8483.html should be imported.
NOTE: If you want to edit the quota directly; it is stored in bytes in the table “mail_users” in a field named “quota”.
You can do it by re-running the installer and changing the default imap server when asked you can choose between courier or dovecot.
There is the global script located in /etc/dovecot/sieve/dovecot.sieve, it can be edited to suit your needs with more functionality. In the default install it moves all the mails tagged as spam to the Junk folder of the mail user, if for some reason you don't have that script created, the content should be this one:
require "fileinto"; if exists "X-Spam-Flag" { if header :contains "X-Spam-Flag" "YES" { fileinto "INBOX.Junk"; stop; } }
More info about sieve syntax and usage: http://wiki.dovecot.org/LDA/Sieve
By doing a small change in postfix configuration, we can use the domain alias as a mail ailas. Being example2.com an alias of example1.com, whenever we create a mailbox in example1.com the same mailbox in example2.com becomes a redirection. So creating [email protected] will also receive the mail from [email protected] automatically. That can be used when a customer don't want the hassle of managing two mail domain (and having to set manually every mail address two times).
/etc/postfix/mysql_virtual_domains.cf
user = DATABASE_USER password = DATABASE_PASSWORD hosts = 127.0.0.1 dbname = DATABASE_NAME query = (SELECT domain_name FROM domain_aliasses INNER JOIN domain ON domain_aliasses.domain_id=domain.domain_id WHERE domain.domain_status='ok' AND domain.domain_mailacc_limit > '-1' AND domain_aliasses.alias_name='%s') UNION (SELECT domain_name FROM domain WHERE domain.domain_status='ok' AND domain.domain_mailacc_limit > '-1' AND domain_name='%s')
/etc/postfix/mysql_virtual_forwards.cf
user = DATABASE_USER password = DATABASE_PASSWORD hosts = 127.0.0.1 dbname = DATABASE_NAME query = SELECT DISTINCT CONCAT(CONCAT(mail_users.mail_acc, "@"), domain.domain_name) from mail_users INNER JOIN domain ON mail_users.domain_id = domain.domain_id INNER JOIN domain_aliasses ON domain.domain_id = domain_aliasses.domain_id WHERE domain_aliasses.alias_name = '%d' AND mail_users.mail_acc = '%u'
If you want the subdomains to be able to receive mail create this file: /etc/dovecot/dovecot-sql-subdomain.conf with the following content:
driver = mysql connect = host=localhost dbname=imscp user=imscp_dovecot password=PASS_MAILRW user_query = SELECT CONCAT('/var/mail/virtual/', subdomain.subdomain_name, ".", domain.domain_name, '/',mail_acc) AS home, '1001' AS uid, '8' AS gid FROM (mail_users INNER JOIN subdomain ON mail_users.sub_id = subdomain.subdomain_id) INNER JOIN domain ON mail_users.domain_id = domain.domain_id WHERE mail_acc='%n' and concat(subdomain.subdomain_name,".",domain.domain_name)='%d';
If you want the domains alias to be able to receive mail:
/etc/dovecot/dovecot-sql-aliasdomain.conf
with the following content:
(In the sql for user_query there are uids and gids 'hardcoded'. The uid must be the uid of vmail user and gid the gid of the mail group. Maybe you have to change the defaults (1001/8))
driver = mysql connect = host=localhost dbname=imscp user=imscp_dovecot password=PASS_MAILRW user_query = SELECT concat('/var/mail/virtual/', domain_aliasses.alias_name, '/',mail_acc) as home, '1001' as uid, '8' as gid FROM (mail_users INNER JOIN domain_aliasses ON mail_users.sub_id = domain_aliasses.alias_id) INNER JOIN domain ON mail_users.domain_id = domain.domain_id WHERE mail_acc='%n' and domain_aliasses.alias_name ='%d';
You have to add in dovecot.conf (section “auth default”):
userdb sql { args = /etc/dovecot/dovecot-sql-subdomain.conf } userdb sql { args = /etc/dovecot/dovecot-sql-aliasdomain.conf }
The parameters for master.cf in postfix need to be changed according the architecture of the system:
for Debian Squeeze (dovecot >= 1.2)
dovecot unix - n n - - pipe flags=DRhu user=vmail argv=/usr/lib/dovecot/deliver -d ${recipient} -s
for Debian Lenny (dovecot >= 1.0.15)
dovecot unix - n n - - pipe flags=DROhu user=vmail:mail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${recipient} -s
for *BSD dovecot from port
dovecot unix - n n - - pipe flags=DROhu user=vmail:mail argv=/usr/local/libexec/dovecot/deliver -f ${sender} -d ${recipient} -s
for CentOS it should be something like this:
dovecot unix - n n - - pipe flags=DROhu user=vmail:mail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}
NOTE: In the SQL query for user_query there are uids and gids 'hardcoded'. The uid must be the uid of your vmail user and gid the gid of the mail group. Maybe you have to change the defaults (1001/8))