Solved Postfix quota email notification

Hi,

I have been trying to get email quota notification working ever since I started using sophimail but never managed to get my script to work. Neither the admin or the users are receiving email email warning
I have created the following files:
/usr/local/bin/quota-warning.sh
Code:
#!/bin/sh
#
# Purpose: Mail to user when his/her quota exceeds specified percentage.
# Reference: http://wiki2.dovecot.org/Quota/Configuration#Quota_warnings
#

PERCENT=$1
USER=$2
cat << EOF | /usr/local/libexec/dovecot/dovecot-lda -d $USER -o "plugin/quota=maildir:User quota:noenforcing"
From: no-reply@mydomain.co.uk
BCC: alert@mydomain.co.uk
Subject: Mailbox Quota Warning: ${PERCENT}% Full, ${USER}.

Hello,

This is a friendly email to inform you that the email account ${USER} is currently ${PERCENT}% full.

<strong>WHAT HAPPENS WHEN MY MAILBOX IS FULL?</strong>
If your mailbox becomes full on the server, you will stop receiving new emails. People who email you will usually receive an email informing them that their message was not delivered because your mailbox is full.

<strong>HOW CAN I CHECK MY MAILBOX QUOTA?</strong>
- Log into your webmail account here: https://mydomain.co.uk/webmail
- Your quota usage is shown on the home page in the lower left corner.

<strong>WHAT SHOULD I DO TO PREVENT MY MAILBOX TO BE FULL?</strong>
- Save large email attachments to your local computer.
- Delete draft emails no longer needed from your drafts folder.
- Remove attachments from sent emails in your sent folder.
- Delete sent emails no longer needed from your sent folder.

<strong>Note:</strong> Deleted email is sent to the bin/trash folder, which is included in your quota. To permanently delete email, empty the bin/trash folder.

<strong>NEED MORE HELP?</strong>
If you need further assistance in solving this issue, please login to https://mydomain.co.uk/support/ and log a ticket with our support department who will be happy to help.

<strong>WARNING:</strong> Do not ignore this message - if your mailbox quota exceeds 100% all incoming email will be rejected.

** THIS MESSAGE WAS AUTOMATICALLY CREATED BY MAIL DELIVERY SOFTWARE. **
EOF
/usr/local/etc/dovecot/conf.d/90-quota.conf
Code:
##
## Quota configuration.
##

# Note that you also have to enable quota plugin in mail_plugins setting.
# <doc/wiki/Quota.txt>

##
## Quota limits
##

# Quota limits are set using "quota_rule" parameters. To get per-user quota
# limits, you can set/override them by returning "quota_rule" extra field
# from userdb. It's also possible to give mailbox-specific limits, for example
# to give additional 100 MB when saving to Trash:

plugin {
  #quota_rule = *:storage=1G
  #quota_rule2 = Trash:storage=+100M
}

##
## Quota warnings
##

# You can execute a given command when user exceeds a specified quota limit.
# Each quota root has separate limits. Only the command for the first
# exceeded limit is excecuted, so put the highest limit first.
# The commands are executed via script service by connecting to the named
# UNIX socket (quota-warning below).
# Note that % needs to be escaped as %%, otherwise "% " expands to empty.

plugin {
  quota_warning = storage=95%% quota-warning 95 %u
  quota_warning = storage=90%% quota-warning 90 %u
  quota_warning2 = storage=80%% quota-warning 80 %u
}

# Example quota-warning service. The unix listener's permissions should be
# set in a way that mail processes can connect to it. Below example assumes
# that mail processes run as vmail user. If you use mode=0666, all system users
# can generate quota warnings to anyone.
service quota-warning {
  executable = script /usr/local/bin/quota-warning.sh
  user = dovecot
  unix_listener quota-warning {
    user = vmail
  }
}

##
## Quota backends
##

# Multiple backends are supported:
#   dirsize: Find and sum all the files found from mail directory.
#            Extremely SLOW with Maildir. It'll eat your CPU and disk I/O.
#   dict: Keep quota stored in dictionary (eg. SQL)
#   maildir: Maildir++ quota
#   fs: Read-only support for filesystem quota

plugin {
  #quota = dirsize:User quota
  #quota = maildir:User quota
  #quota = dict:User quota::proxy::quota
  #quota = fs:User quota
}

# Multiple quota roots are also possible, for example this gives each user
# their own 100MB quota and one shared 1GB quota within the domain:
plugin {
  #quota = dict:user::proxy::quota
  #quota2 = dict:domain:%d:proxy::quota_domain
  #quota_rule = *:storage=102400
  #quota2_rule = *:storage=1048576
}

plugin {
  quota = dict:User quota::proxy::quota
  quota_rule2 = Trash:storage=+100M
}

Could someone please help me figure this one out?

Thank you
 
Why don't you want to keep an eye on the postfixadmin, which does a greater part what you want to do? You might want to take a look at its scripts.
 
Back
Top