• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

mailbox notification when full

L

Lucien

Guest
Hello,

I would like to know how can my clients get warned when they exceed their mailbox quota ?

I mean : Mr x gets his mailbox full but nothing is made in order to notify him about that, besides, people who send e-mails to him get a message that told them Mr x's mailbox is full.

Is there any way to warn Mr x when his mailbox is full ?

thx
 
i use a daily cronjob with a shellscript as follows. it sends a warning message, if the mailbox uses more than 85% ( see formula for SOFTQUOTA).

it is far from perfect, there are still some things to add
1. error correction, if quota is set to zero
2. script can not remember, if it has allready sent a warning, so inactive mailboxes will be filled with warning messages
3. if mailbox allready exceeds hardquota, the warning message will not get through.

i thought about adding some database support to the script to remember sent warnings and writing the warning directly into the mailbox directory, but have not done this because it works as is in 99.9% percent of the cases.



Code:
#! /bin/sh
# warn plesk mailbox users, if mailbox exceeds quota
#
#setenv QMAILUSER 'do-not-reply'
MAILROOT=/var/qmail/mailnames
ADMINMSG=''
cd $MAILROOT > /dev/null
for DIR in *.*;do
QUOTAFILE=$MAILROOT/$DIR/@mbox.quota
# if domainquota exists
if [ -f $QUOTAFILE ]
        then
        DOMAINHARDQUOTA=`cat $QUOTAFILE`
        DOMAINSOFTQUOTA=$((85 * $DOMAINHARDQUOTA / 100))
        #echo "$DIR $DOMAINHARDQUOTA - $DOMAINSOFTQUOTA"
        cd $MAILROOT/$DIR
        for MAILBOX in * ;do
                if [ -d $MAILBOX ]
                        then
                        # look for specific mailbox quota file and set mailbox softquota
                        QUOTAFILE=$MAILROOT/$DIR/$MAILBOX/@mbox.quota
                        #echo $QUOTAFILE
                        if [ -f $QUOTAFILE ]
                        then
                          HARDQUOTA=`cat $QUOTAFILE`
                          #echo "using specific $QUOTAFILE, $HARDQUOTA"

                          SOFTQUOTA=$((85 * $HARDQUOTA / 100))
                        else
                          #echo "using domainquota"
                           HARDQUOTA=$DOMAINHARDQUOTA
                          SOFTQUOTA=$DOMAINSOFTQUOTA
                        fi
                        # calculate space used by mailbox
                        MBOXSPACE=`du -ks $MAILBOX | cut -f1`
                        #echo "$MAILBOX@$DIR uses $MBOXSPACE"
                         if [ $HARDQUOTA -gt 0 -a $MBOXSPACE -gt $SOFTQUOTA  ]; then
                        MBOXPERCENT=$(($MBOXSPACE * 100 / $HARDQUOTA))
                        echo "$MAILBOX@$DIR belegt $MBOXSPACE kb, Soft/Hardquota = $SOFTQUOTA kb /$HARDQUOTA kb"

#for testing: send warn mail to postmaster account
#mail  -r do-not-reply@$DIR -s "Mailbox Quota Warnung" [email][email protected][/email] << EOF
#
#regular: send warn mail to mailbox
mail  -r do-not-reply@$DIR -s "Mailbox Quota Warnung" $MAILBOX@$DIR << EOF


Dear $MAILBOX

Your Mailbox currently uses $MBOXSPACE kb ($MBOXPERCENT %) on the mailserver. We would like to
remind you that your mailbox may only contain $HARDQUOTA kb.

To avoid problems when receiving new mail, you should remove read mail from the server.


Regards,
mailbox-robot
EOF



                        fi
                fi
        done;

fi



done;
cd /root/bin
 
I have 2 isues, but I tried on 7.5.x

1. Your Mailbox currently uses 5488 kb (-548800 %) on the mailserver. We would like to
remind you that your mailbox may only contain -1 kb.

2. -r do-not-reply@$DIR not work. So I need to use without it.

Any ideea on issue 1?
 
Originally posted by lvalics
I have 2 isues, but I tried on 7.5.x

1. Your Mailbox currently uses 5488 kb (-548800 %) on the mailserver. We would like to
remind you that your mailbox may only contain -1 kb.

2. -r do-not-reply@$DIR not work. So I need to use without it.

Any ideea on issue 1?

solution for issue 1:

if a mailbox-quota for a domain is set to unlimited, plesk writes -1 into the quota file. i have corrected my previous post to avoid the error .

replace the old if construct:
Code:
if [ $MBOXSPACE -gt $SOFTQUOTA  ]; then
with
Code:
if [ $HARDQUOTA -gt 0 -a $MBOXSPACE -gt $SOFTQUOTA  ]; then


issue 2 depends on the implementation of the mail command on your distribution, in my case this is nail and

-r address Sets the From address.

maybe you can find the corresponding option in the manpages for mail.
 
what mailer do you use?

issue 2 depends on the implementation of the mail command on your distribution, in my case this is nail and

-r address Sets the From address.

maybe you can find the corresponding option in the manpages for mail.
nail? We use sendmail.
 
OK, a suggestion.
As I saw now the script will get user emails.
In many cases the quota is on domain, not on users. Can this be get and use also domain quota if no user quota and send a mail to admin of domain owner??
 
I would like to believe that there is another way to inform the users than a personnal script. I don't understand why this option is not available by default somewhere in plesk. And besides that, there is something complelety stupid : the sender of the email get the error message that says the mailbox is full, i think the other way would be more convenient...
 
I wrote a script which is working for PLESK 9.5.3. This Script reads the maildirsize-files in the given MAILROOT-directory and sends emails.

The mailbody is defined in german language but feel free to use this script and change it regarding to your needs

#!/bin/bash
# Shell Script utility to read the maildirsize file.
# If the mailbox of some user inside the MAILROOT-Directory is over the defined MAXPERCENTAGE
# a mail is sent to this user
# -------------------------------------------------------------------------

# User define Function (UDF)
processLine(){
line="$@" # get all args
if [ $COUNTER -eq 0 ]
then
HARDQUOTA=$(echo $line | cut -d "S" -f 1)
else
ACTUALSIZE=$(echo $line | awk '{ print $1 }')
MBOXSPACE=$(( $MBOXSPACE + $ACTUALSIZE ))
fi
}

### Main script starts here ###
###
# Counter
COUNTER=0

# Maximum Percentage of Quota usage
MAXPERCENTAGE=80

###
#
MAILROOT=/srv/email/mailnames
cd $MAILROOT > /dev/null
for DIR in *.*; do
cd $MAILROOT/$DIR > /dev/null
for MAILBOX in *; do
if [ -d $MAILROOT/$DIR/$MAILBOX ]; then
FILE=$MAILROOT/$DIR/$MAILBOX/Maildir/maildirsize
fi

if [ -f $FILE ]; then
# Set loop separator to end of line
while read -r line
do
# use $line variable to process line in processLine() function
processLine $line
(( COUNTER ++ ))
done < $FILE

#reset COUNTER to 0 for the next file
COUNTER=0
if [ $HARDQUOTA -gt 0 ]; then
SOFTQUOTA=$(( $MAXPERCENTAGE*$HARDQUOTA/100 ))
MBOXPERCENT=$(( $MBOXSPACE*100/$HARDQUOTA ))
fi
#echo "Quota is $HARDQUOTA, used $MBOXSPACE, softquota is $SOFTQUOTA, in Prozent $MBOXPERCENT"
if [ $HARDQUOTA -gt 0 -a $MBOXSPACE -gt $SOFTQUOTA ]; then
echo "$MAILBOX@$DIR belegt $MBOXSPACE bytes, Soft/Hardquota = $SOFTQUOTA bytes/$HARDQUOTA bytes, in Prozent $MBOXPERCENT"
#mail -r do-not-reply@$DIR -s "Mailbox Quota Warnung" [email protected] << EOF
mail -r do-not-reply@$DIR -s "Mailbox Quota Warung" $MAILBOX@$DIR << EOF
Liebe(r) $MAILBOX

Deine Mailbox nutzt im Moment $MBOXSPACE b ($MBOXPERCENT %) auf dem Mailserver. Wir wuerden dich gerne erinnern
dass deine Mailbox nur $HARDQUOTA b beinhalten darf.

Um Probleme zu vermeiden, entfernen Sie bitte Mails in Ihrem Posteingang, Gesendeten Objekten und allen Unterordnern

Liebe Gruesse,
mailbox-robot

EOF
fi
#reset all variables to 0 in order to process the next file
HARDQUOTA=0
MBOXSPACE=0
SOFTQUOTA=0
fi
done
done

exit 0
 
This script has been running prefectly from the first day, but now suddenly it get the following error:
(standard_in) 1: syntax error
Debugging I realized that comes by "bc" command to get the space. Can you help me to fix the script?
I currently use Plesk Panel 12
 
This script has been running prefectly from the first day, but now suddenly it get the following error:
(standard_in) 1: syntax error
Debugging I realized that comes by "bc" command to get the space. Can you help me to fix the script?
I currently use Plesk Panel 12

Would you please post your script here? I will have a look.
 
Back
Top