Deleting All Catch-All Mails Across All Accounts

arsytym

Registered
Nov 20, 2014
2
0
1
cPanel Access Level
Root Administrator
Hi,
I need to empty all my catch-all accounts, I have many to do which will take a long time manually

I already set the catch-all to : Fail to prevent more mail coming in,

I have probably over 1 million emails in total collectively in these accounts, some have over 200k so
trying to remove cur folder times out.

Any ideas what to run with SSH to do this in bulk?

Thank you
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,218
463
Hello :)

Email sent to the default address is stored in:

Code:
/home/$username/mail/cur
/home/$username/mail/new
You can delete all of this email through the use of a wildcard and the "rm" command. There is no single command to use, but you could try something such as:

Code:
mkdir /root/email-to-delete
mv /home/*/mail/cur/* /root/email-to-delete/
mv /home/*/mail/new/* /root/email-to-delete/
Then, simply delete "/root/email-to-delete" when you have confirmed the emails are no longer required.

To note, you can ensure emails sent to non-existent email accounts are not delivered to the default address by ensuring your accounts set the "Default Address" to:

"Discard with error to sender (at SMTP time)"

Thank you.
 

arsytym

Registered
Nov 20, 2014
2
0
1
cPanel Access Level
Root Administrator
Hello,

Thank you for replying to my question.

I ran the command,

mv /home/*/mail/cur/* /root/email-to-delete/


But I received This:

-bash: /bin/mv: Argument list too long


I have set all existing account to :fail now - just need to clear out these folders :)
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,218
463
You may find this third-party application helpful if you lack command-line experience:

Config Server Mail Manage

Otherwise, searching for "/bin/mv: Argument list too long" on a search engine will yield useful results.

Thank you.
 

ethical

Well-Known Member
Apr 7, 2009
96
8
58
just wanted to save others the time in "searching for the answer" as Michael suggested

use
Code:
find /home/*/mail/cur/* -type f | xargs -i mv "{}" /root/email-to-delete/

or this and slowly increase the mtime value until you can finish with the above line

find /home/*/mail/cur/* -type f -mtime +1 -print | xargs -i{} mv {} /root/email-to-delete/
in my cause my list was even too long for the find command, even when i set it to just do files modified in the lastday (-mtime +1) so i did this and stepped through the alphabet for the home dirs util I could run the above command without error

Code:
find /home/a*/mail/new/* -type f -print | xargs -i{} mv {} /root/email-to-delete/
 
Last edited: