SOLVED Delete old emails

jnorris235

Registered
May 19, 2017
3
1
3
England
cPanel Access Level
Reseller Owner
In order to delete emails over 6 months old, that are sat in an INBOX (and NOT in any other folders created by client) would somebody be kind enough to offer a php script?
I understand I can put this script in my public_html directory and call for it to run by a CRON command such as > /home/cPaneluser/public_html/yourscript.php
It would seem the easiest way for me as I can understand php, but not bash scripts or other suggestions I have read.

I apologise for being out of my depth reading other replies - but it appears also to me that they would delete ALL emails over 6 months old (for example) and not just those in a specified mailbox. Your patience appreciated!
 

24x7server

Well-Known Member
Apr 17, 2013
1,912
99
78
India
cPanel Access Level
Root Administrator
Twitter
Hi,

If you want to perform this deletion activity through PHP, then you may end up enabling some PHP vulnerable function that is required to actually execute the removal command, in an attempt you may get in trouble with opening your server for attacks. Please be careful...

A bash script would be perfect way for you to do this..
Hint: You can remove the mails from the "cur" folder that has the new and current emails..
 

jnorris235

Registered
May 19, 2017
3
1
3
England
cPanel Access Level
Reseller Owner
Hi,

If you want to perform this deletion activity through PHP, then you may end up enabling some PHP vulnerable function that is required to actually execute the removal command, in an attempt you may get in trouble with opening your server for attacks. Please be careful...


>> That sounds like good advice - thank you.

A bash script would be perfect way for you to do this.
Hint: You can remove the mails from the "cur" folder that has the new and current emails..
>> What do I actually do with a bash script - can it made to run automatically (via a cron job perhaps?)
 

Infopro

Well-Known Member
May 20, 2003
17,075
524
613
Pennsylvania
cPanel Access Level
Root Administrator
Twitter
would somebody be kind enough to offer a php script?
Not sure why you'd need a script for this when it can be done from in your cPanel easy enough.
cPanel > Email > Email Accounts > choose an email account you'd like to clean up by clicking the More menu to the right of the email account listed here, then select Manage Disk Usage. Click Manage to the right for some options.

Will this fit your needs?

mngdskusgsttngs.jpg
 

jnorris235

Registered
May 19, 2017
3
1
3
England
cPanel Access Level
Reseller Owner
That is absolutely perfect, thought I'd investigated everything on cPanel, many google searches, then got bogged down with similar threads using more esoteric stuff. Very grateful for your time!
 
  • Like
Reactions: Infopro

vanessa9909

Registered
Sep 12, 2017
1
0
1
brazil
cPanel Access Level
Website Owner
Not sure why you'd need a script for this when it can be done from in your cPanel easy enough.
cPanel > Email > Email Accounts > choose an email account you'd like to clean up by clicking the More menu to the right of the email account listed here, then select Manage Disk Usage. Click Manage to the right for some options.

Will this fit your needs?

View attachment 46915
Hello
I would like to know which command I can use to delete messages that are 6 months or older.
And not from 1 year or more.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,268
463
I would like to know which command I can use to delete messages that are 6 months or older.
And not from 1 year or more.
Hello,

You can use the same option in cPanel:

Email Disk Usage - Version 68 Documentation - cPanel Documentation

Note the following under the "Remove Messages" section:

Select custom query ... to customize your removal option. For more information, read Dovecot's Search Query Format documentation.
EX:

Code:
savedbefore 26weeks
Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,268
463