How to delete all emails older than x days?

electric

Well-Known Member
Nov 5, 2001
790
11
318
Is there any way for cpanel users to set up a regular (automated) action to delete emails older than x days?

(Customer is using "mdbox" mail storage format.)

Thanks.
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,304
363
Houston

wsherwood

Member
May 21, 2010
10
1
51
Error with built-in dropdown custom query chosen:
[Manage]
Email DIsk Usage>>
Messages to delete:
[Custom query...] 3 months or more older [Delete permanently]
Error: “/usr/bin/doveadm” reported error code “75” when it ended: Fatal: Unknown argument MONTHS

Question: why is there a cPanel-offered choice that apparently has bad syntax? ("months")

(Their suggestion example: " savedbefore 2weeks" does work even tho it seemingly is missing a space, and the term "saved" isn't logical, in this case it's "received")

All this is difficult to explain to complaining clients
 

wsherwood

Member
May 21, 2010
10
1
51
3 months or more older
was one of the drop down choices. If the script provides a choice, i would want it to be correct syntax/keywords.
if it's not meant to be an example of syntax and instead just a loose description, then it should be labeled and offer the resulting/desired correct syntax to achieve the date range.
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
16,634
2,629
363
cPanel Access Level
Root Administrator
The reason I asked is because I'm not seeing that in the options in my interface. I'm on the latest build, which is 102.0.14, and I see this in the main area:

Screen Shot 2022-05-04 at 7.47.34 PM.png

but I don't see anything automatically populate when I either move my cursor into, or start typing into, the text box. I did test this on an account with many emails going back several years, both in Jupiter and Paper Lantern, and I'm not seeing the "3 months" option appear.

Can you let me know what version of cPanel you're working with, and also provide a screenshot?
 

wsherwood

Member
May 21, 2010
10
1
51
[sorry for the delay, i don't see my reply to your last message posted, grrr. I'll reconstruct it]
( this is not a showstopper, but several times a week in support roles, we guide our clients thru similar)

102.0.12 (STANDARD) CentOS v7.9.2009
[specific email account]
MANAGE EMAIL ACCOUNTS
Free up Email Storage
1652204339586.png
Clarification/correction: the following is not a dropdown, but rather autofill choices. Perhaps therein is the predicament (it might be populating suggestions from an unrelated similarly named input field somewhere)
So assuming that is the case, then the suggestion is to have a tooltip popup of syntax options more than just. ("savedbefore" is not obvious)
It takes a bit of drilling down in the dovecot links to find:

1652204434290.png
So assuming that is the case, then the suggestion is to have a tooltip popup of syntax options more than just. ("savedbefore" is not obvious)
It takes a bit of drilling down & scrolling down in the dovecot links to find which are not obvious that this is syntax for this usage.
Maybe make the link for help point directly (and only) to Tools/Doveadm/SearchQuery - Dovecot Wiki#section_date_specification
1652204749027.png


Thank you!
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
16,634
2,629
363
cPanel Access Level
Root Administrator
Thanks for that - that's exactly what I needed to know.

This leads me to another issue - both myself and a colleague, on two separate browsers each, aren't getting those dropdown prompts. Can you try a different browser at your location and see if you're still getting those?
 

wsherwood

Member
May 21, 2010
10
1
51
you are correct. in another browser the autofill suggestions are not there.
sorry for the trouble.
(may i still suggest to put a link directly to the syntax options)

thank you
will
 

Rachel S

Member
Apr 28, 2022
24
5
3
United States
cPanel Access Level
Website Owner
Step 1: First, you need to set the cron using cPanel.

Now to set the cron you,
open the cPanel, Scroll down
Advanced > Cron jobs.

Step 2: Add the command mentioned below to run in the cron.

/usr/bin/archivemail –quiet –delete –days 20 /home/{USER}/mail/inbox

The emails will be auto-deleted for older than 20 days using the above command.
 

4EverMaAT

Registered
Jun 28, 2023
1
0
0
Thailand
cPanel Access Level
Website Owner
Error with built-in dropdown custom query chosen:
[Manage]
Email DIsk Usage>>
Messages to delete:
[Custom query...] 3 months or more older [Delete permanently]
Error: “/usr/bin/doveadm” reported error code “75” when it ended: Fatal: Unknown argument MONTHS

Question: why is there a cPanel-offered choice that apparently has bad syntax? ("months")

(Their suggestion example: " savedbefore 2weeks" does work even tho it seemingly is missing a space, and the term "saved" isn't logical, in this case it's "received")

All this is difficult to explain to complaining clients

I saw this and just recently did it myself so I would provide an answer. I originally assumed like you to use the phrase "X months or more older" and kept getting the same error you did.

So I decided to do "savedbefore 26weeks" which is 6 months. And it worked. So you just have to estimate your request in weeks. Haven't tried days. But I assume if you want higher precision, you would need to use "days" or "minutes".