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:
<?
require_once('ispconn.php');
require_once('phpmail.php');
$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);
$precent= round($precent);
//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 .= "Quickspace.co.za Support";
$body = $body;
$mail = new PHPMail();
$mail->IsMail();
$mail->Sender = "me@mydomain.com";
$mail->FromName = "My Name";
$mail->From = "me@mydomain.com";
$mail->AddAddress("me@mydomain.com");
$mail->AddAddress($email);
$mail->IsHTML(true);
$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 (!$mail->Send()){
echo "sendmail error";
}
}
}
}
}
?>
Recent comments
20 hours 28 min ago
23 hours 23 min ago
1 day 37 min ago
1 day 2 hours ago
1 day 3 hours ago
1 day 5 hours ago
1 day 6 hours ago
1 day 22 hours ago
1 day 23 hours ago
2 days 2 hours ago