Cron to delete the old E-mails

You can ask your hosting provider to add the cron in the server main crontab file to delete the old mails from your hosting account or you can also create the new file with the following code and set the 755 permission to file and set the cron job from the cPanel as per yout requirement.

Create the new file name mail-delete.sh and add the following code in the file.

#!/bin/bash
cd /home/cpanel-user-name/mail/domain.com/mail-account-name/new/;
rm -rf *;

In above code replace the following values as per your original values.

cPanel-user-name : your original cPanel user name
Domain.com : your original domain name
mail-account-name : mail account name under which you want to delete the mails
new : if you want to delete all the new mails than use new and if you want to delete all the read mails than replace new to cur.

Note : Do not use the -r option with the rm command because mails are files and no need to use -r option.

About Anant 376 Articles
Senior technical writer