Step1 : create a file named "deljunk.php"on your server root
deljunk.php :
Step2 : Create a cron task to run every nigth
add at the end:
Code:
cd
nano deljunk.php
deljunk.php :
PHP Code:
<?php
define ("DB_HOST", "localhost"); // set database host
define ("DB_USER", "postfix"); // set database user
define ("DB_PASS","XXXXXXXXXXXXXXXXXXX"); // set database password
define ("DB_NAME","sentora_postfix"); // set database name
$email = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) or die("Couldn't make connection.");
$getMailsDisplay = $email->query("SELECT username FROM `mailbox`");
foreach($getMailsDisplay as $array){
foreach($array as $key=>$value){
echo $value."|";
shell_exec("doveadm expunge -u $value mailbox Junk savedbefore 15d");
shell_exec("doveadm expunge -u $value mailbox Trash savedbefore 15d");
}
}
?>
Step2 : Create a cron task to run every nigth
Code:
crontab -e
add at the end:
Code:
30 4 * * * php deljunk.php