LMTP quota limit notifications sending extra notification to admin email

satankoh666

Verified User
Joined
Feb 2, 2020
Messages
17
Hi experts

I follow this post: https://help.directadmin.com/item.php?id=625 to add a quota limit notification where the system will send out notification email to users when their email hit 80%, 90% and 100% of their quota, and it works like a charm.

However, is there a way that I can tweak the script to ALSO send an notification to a specific email like the admin email?


This is the steps that i followed:

cd /etc/dovecot/conf.d
wget -O 91-quota-warning.conf http://files1.directadmin.com/services/all/91-quota-warning.conf
wget -O /usr/local/bin/quota-warning.sh http://files1.directadmin.com/services/all/quota-warning.sh
chmod 755 /usr/local/bin/quota-warning.sh


This is the script in the quota-warning.sh

#!/bin/bash
PERCENT=$1
USER=$2
DOMAIN=$3
FROM=$USER

if [ "$#" -eq 0 ]; then
echo "Usage: $0 <percent> <email> <domain>";
exit 1;
fi

cat << EOF | /usr/libexec/dovecot/dovecot-lda -d $USER -o "plugin/quota=maildir:User quota:noenforcing"
From: $FROM
Subject: Email Quota Usage: $PERCENT%

This is an automated notification letting you know that your account:
$USER

has used $PERCENT% of it's available space.

EOF


Thanks in advanced
Ron
 
However, is there a way that I can tweak the script to ALSO send an notification to a specific email like the admin email?

In your quota-warning.sh script, you could maybe do something like this (code requires grep, curl, and jq, and is not really tested, and contains no validation):

Code:
# Get the Directadmin username for the domain
domain_username="$(grep -oP "^${3//./\\.}: \K.*(?=$)" /etc/virtual/domainowners)"

# Use the Directadmin API to get the registered email for the account
admin_email="$(curl -s $(/usr/local/directadmin/directadmin api-url)/api/users/${domain_username}/config | jq -r .email)"

Then assuming $admin_email contains a valid address you could send an e-mail to them as well. Note that you might not want to use dovecot-lda since $admin_email could be an any external address. Alternatives like mail or mutt or some other generic tiny mail client could be used.
 
Last edited:
Back
Top