View Single Post
Old 26th January 2013, 13:31
Darkfire Darkfire is offline
Junior Member
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

Hi All

Here is a PHP script I wrote some time ago that uses phpmail to send the notification. For those who are more conformable with PHP. You probably want to change the SQL statement to select mailboxes that are active, or only select whose with a quota.

Not a fast script as it uses the "du" command line to get the size of the mailbox folder, so probably not great if you have thousands of email boxes to check

Place a job in the crontab to run once a day.

PHP Code:

$sql "select * from mail_user";
$rs mysql_query($sql);

$rowcount mysql_num_rows($rs);
//echo $rowcountm;

if ($rowcount 0){

        while (
$row mysql_fetch_object($rs)){
$over false;
//0 is unlimited
if ($row->quota 0){

$domain = array();
$domain explode('@',$row->email);
$dn $domain[1];
$email $domain[0];
$path '/var/vmail/' $dn "/" $email "/";
$output exec('du -s ' $path);
$foldersize = array();
$foldersize explode("/",$output);
$totalsize trim(($foldersize[0]/1024));
$totalsize round($totalsize);
//echo $totalsize . chr(10);

$quota round(($row->quota/1024)/1024);

$precent = (($totalsize $quota) * 100);
//If the folder is over 95 % then try to send a message
if ($precent >= 95){

$email $row->email;
$subject "MailBox Full Size Notification" ;

$body "<html>";
$body .= "<body>";
$body .= "Dear User<p>";
$body .= "Please note that your email box for "$email " is " $precent "% full. <p>";
$body .= "Your mailbox size limit on the server is set to " $quota ."MB and your current usage is ".$totalsize "MB<p>";
$body .= "Mail delivery to your email address may be delayed and some mail might not come through. <p>";
$body .= "Please clear out some of your email<p>";
$body .= "Regards,<BR>";
$body .= " Support";

$body $body;
$mail = new PHPMail();
$mail->Sender "";
$mail->FromName "My Name";
$mail->From "";
$mail->Subject $subject;
$mail->Body $body//Message body in HTML format
$mail->AltBody $body//Message in Plain text if recepients mail client doesnt support html mail
$mail->WordWrap 50;
                                if (!
"sendmail error";

Last edited by Darkfire; 26th January 2013 at 13:36.
Reply With Quote