User Tools

Site Tools


start:howto:dovecot_plus_database_quota

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
start:howto:dovecot_plus_database_quota [2012/01/10 08:38]
aseques
start:howto:dovecot_plus_database_quota [2012/08/23 08:29]
aseques
Line 8: Line 8:
 ===== Changes from standard dovecot in imscp ===== ===== Changes from standard dovecot in imscp =====
   * Alias and subdomains can be used as a full mail domains   * Alias and subdomains can be used as a full mail domains
-  * Warning users that are overquota+  * Global sieve filtering
  
 ===== Reasons to use dovecot ===== ===== Reasons to use dovecot =====
Line 18: Line 18:
   * You can block users after they are exceeding their quotas.   * You can block users after they are exceeding their quotas.
   * Dovecot is really fast and reliable   * Dovecot is really fast and reliable
 +  * Warning users that are overquota
  
 Please report any bugs/​hints/​whatever in the following board thread: Please report any bugs/​hints/​whatever in the following board thread:
Line 32: Line 33:
 ===== Optional features ===== ===== Optional features =====
  
-==== Sieve filtering ====+==== Global sieve filtering ====
  
 There is the global script located in /​etc/​dovecot/​sieve/​dovecot.sieve,​ it can be edited to suit your needs with more functionality. 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.+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: 
 + 
 +<​code>​require "​fileinto";​ 
 +if exists "​X-Spam-Flag"​ { 
 + if header :contains "​X-Spam-Flag"​ "​YES"​ { 
 +       ​ fileinto "INBOX.Junk";​ 
 + stop; 
 +
 +}</​code>​ 
 + 
 + 
 More info about sieve syntax and usage: http://​wiki.dovecot.org/​LDA/​Sieve More info about sieve syntax and usage: http://​wiki.dovecot.org/​LDA/​Sieve
  
-==== Use domain alias as mail alias too ====+==== Use domain alias/​subdomain ​as mail alias ====
  
 By doing a small change in postfix configuration,​ we can use the domain alias as a mail ailas. By doing a small change in postfix configuration,​ we can use the domain alias as a mail ailas.
Line 76: Line 88:
 </​code>​ </​code>​
  
-==== Automatically alert user if his quota exceeds a critical limit ==== +If you want the subdomains ​to be able to receive mail create ​this file: 
-You can configure Dovecot ​to execute an external command if an user's quota exceeds a specified limit. In this example the user receives alert emails if his quota exceeds 80% 95% percent.+**/etc/​dovecot/​dovecot-sql-subdomain.conf**  
 +with the following content:
  
-Append the following in your plugin section in **/etc/dovecot/dovecot.conf**:+<​code>​ 
 +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';​ 
 +</​code>​
  
-  quota_warning = storage=95%% ​/usr/local/bin/dovecot-quota-warning.sh 95 +If you want the domains alias to be able to receive mail: 
-  ​quota_warning2 = storage=80%% ​/usr/​local/​bin/​dovecot-quota-warning.sh 80+**/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))
  
-If the user's quota reaches the limit the external script dovecot-quota-warning.sh is run. If you define quota warnings make sure that you start with the highest limit because Dovecot only runs the command for the first limit that is exceeded. 
- 
-create **/​usr/​local/​bin/​dovecot-quota-warning.sh** 
-Give appropiate permissions to the file 
-  chmod 755 /​usr/​local/​bin/​dovecot-quota-warning.sh 
 <​code>​ <​code>​
-#!/bin/sh +driver = mysql 
-PERCENT=$1 +connect ​host=localhost dbname=imscp user=imscp_dovecot password=PASS_MAILRW 
-cat << EOF | /usr/lib/dovecot/deliver -d $USER -c /etc/​dovecot/​dovecot-no-quota-warning.conf +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';​
-From: postmaster@yourdomain.tld +
-To: $USER +
-Subject: quota warning +
-Content-Type:​ text/plain; charset="​UTF-8"​ +
- +
-Attention! The emails in your mailbox are using more than $PERCENTof your total mail space. +
-EOF+
 </​code>​ </​code>​
  
-Create **/etc/dovecot/​dovecot-no-quota-warning.conf** \\ +You have to add in dovecot.conf ​(section "auth default"​)
-This is basically the same file as dovecot.conf but the quota rules are stripped out in order to avoid looping. You can strip the quota lines manually or let it grep do for you+  ​userdb sql { 
-  ​grep -v "​quota" ​dovecot.conf > dovecot-no-quota-warning.conf +    args = /etc/dovecot/dovecot-sql-subdomain.conf 
- +  } 
-At last set correct permissions to dovecot-no-quota-warning.conf +  ​userdb sql { 
-  chmod 0644 /​etc/​dovecot/​dovecot-no-quota-warning.conf +    args = /​etc/​dovecot/​dovecot-sql-aliasdomain.conf 
- +  }
-For more information about this have a look at http://​wiki.dovecot.org/​Quota/​1.1+
  
 ===== Frequent issues ===== ===== Frequent issues =====
Line 135: Line 141:
  
 **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)) **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))
- 
-=== Configure Dovecot === 
- 
-If you want the subdomains to be able to receive mail: 
-**/​etc/​dovecot/​dovecot-sql-subdomain.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)) 
- 
-<​code>​ 
-driver = mysql 
-connect = host=localhost dbname=ispcp user=ispcp_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';​ 
-</​code>​ 
- 
-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)) 
- 
-<​code>​ 
-driver = mysql 
-connect = host=localhost dbname=ispcp user=ispcp_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';​ 
-</​code>​ 
/var/www/virtual/i-mscp.net/wiki/htdocs/data/pages/start/howto/dovecot_plus_database_quota.txt · Last modified: 2013/06/21 07:36 by aseques