[Ticket ID: 50488752] Clear Mail By Cron

Windows And Linux VPS Server guides and support
Scott
Support Group
Support Group
Posts: 22
Joined: Tue Apr 30, 2013 6:03 pm
Contact:

[Ticket ID: 50488752] Clear Mail By Cron

Postby Scott » Mon May 11, 2015 4:53 pm

Here I’m going to list the best way to clear mail from a domains mail box which is older than a set period. Support Ticket ID:50488752 requests a way to clear their mail which is older than 15 days via a cron job. Here’s how you would do this using the +mtime handle.

First off we need to create a file anywhere on the server if your using SSH or using notepad on your PC, as I’m completing this ticket whilst also producing this guide I’m going to be using SSH. cPanel uses three folders to manage mail these are;

New: This is where all mail is first received
Cur: Once opened mail is dropped into here
Tmp: This folder contains processed mail for delivery

The default location for these files would be /home/cPanelusername/mail/domain.com/emailbox/cur

NOTE: emailbox represents the mail user folder. (emailbox/ for emailbox@domain.com)

Let’s first create a file we can work inside

Code: Select all

touch emailcleaner.sh

now let’s edit the file

Code: Select all

nano emailcleaner.sh

Next add in the below line to the file

Code: Select all

find /home/cPanelusername/mail/yourdomain.com/EMAILUSER/cur -type f -mtime +15 -exec rm -f {} ;


Save and close the file CTRL + X

Code: Select all

chmod 755 /root/emailcleaner.sh


That’s our file now created. Next we need to add a cron job to run this file, I’m thinking once a day is fine for this script. You could even run it once a week if needed.

If you’re a Reseller your not likely going to have access to the root crontab so the file we just created would need to be placed into your cPanel home directory (/home/cPanelusername) and then create a cron job from your cPanel account like below

Code: Select all

0 0 1 * * /home/cPanelusername/emailcleaner.sh > /dev/null 2>&1


VPS and Dedicated users can add the cron to root by issuing the below command

Code: Select all

Crontab –e 

Code: Select all

0 0 1 * * /root/emailcleaner.sh > /dev/null 2>&1

Who is online

Users browsing this forum: No registered users and 1 guest