===== Email modifications from default imscp install ===== This is an improved version from the original article in ispcp (http://isp-control.net/documentation/howto:mail:replace_courier_with_dovecot) The default install suits most of the needs, so this document is focused to add some functionality that is available only on dovecot (not always in courier). The required dovecot version is now 1.2 (squeeze's default) or newer. ==== Changes from standard mail setup in imscp ==== * Alias can be used as a full mail domains * Global sieve filtering (already enabled by default but without config) ==== Reasons to use dovecot ==== * You can do server-side filtering with sieve (for example saving spam to junk folder) * Reading your logs for problems will be easier * Having custom setups is simpler due to the dovecot config files * All the data is taken from the database, so everything is immediate and you don't rely on scripts * You can block users after they are exceeding their quotas. * Dovecot is really fast and reliable * Warning users that are overquota Please report any bugs/hints/whatever in the following board thread: http://forum.i-mscp.net/showthread.php?tid=61 ==== Replace Courier with Dovecot ==== You can do it by re-running the installer and changing the default imap server when asked you can choose between courier or dovecot. ===== Global sieve filtering ===== Dovecot will look for the global sieve script located in /etc/dovecot/sieve/dovecot.sieve, it can be edited to suit your needs with more functionality. In the sample below, it moves all the mails tagged as spam to the Junk folder of the mail user: 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 ===== Use domain alias as a mail alias ===== 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 admin@example1.com will also receive the mail from admin@example2.com 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). ==== The changes we have to do in postfix ==== In the file main.cf (proposed changes are for the template), from: virtual_mailbox_domains = hash:{MTA_VIRTUAL_DMN_HASH} virtual_alias_maps = hash:{MTA_VIRTUAL_ALIAS_HASH} To: #virtual_mailbox_domains = hash:{MTA_VIRTUAL_DMN_HASH} virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains.cf #virtual_alias_maps = hash:{MTA_VIRTUAL_ALIAS_HASH} virtual_alias_maps = hash:{MTA_VIRTUAL_ALIAS_HASH}, mysql:/etc/postfix/mysql_virtual_forwards.cf /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_aliasses.alias_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 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 } ===== Deprecated documentation (pending to be purged) ===== **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)) ==== Adapt postfix master.cf ==== 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}