Delete all emails in Trash via SSH

marlowmedia

Member
Oct 25, 2016
14
2
3
Wigan
cPanel Access Level
Root Administrator
Hi,

I'm trying to sort my work email out, i have over half a million emails in my Trash folder, using SSH how can i delete all the emails in my email Trash folder?

Its starting to cause a few issues for me with Outlook.

Thanks,
Mike
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,910
2,213
363
Hello,

The following option exists under "WHM Home » Service Configuration » Mailserver Configuration":

"Auto Expunge Trash"

When this option is enabled, the system will remove messages in the Trash and Deleted Messages folders based on the expiration time configured for the "Trash Expire Time" option. Once you have configured this option, you can initiate the removal of the emails manually using the following command:

Code:
/scripts/dovecot_maintenance
Otherwise, you'd need to manually remove the emails from the .Trash directory via SSH. It's located at:

Code:
/home/$username/mail/$domain/$email-account/.Trash
Thank you.
 

marlowmedia

Member
Oct 25, 2016
14
2
3
Wigan
cPanel Access Level
Root Administrator
Code:
[dovecot_maintenance] Setting I/O priority to reduce system load: best-effort: prio 4
Expiring trash for “[email protected]” in the “INBOX.Trash” mailbox …Done
@cPanelMichael I've ran the script and it says its completed removing the emails from my account but they are still all there?

So moving onto the second option you gave you said i have to delete all the emails in the directory, can you explain a little more exactly what im deleting as within the directory you told me theres other folders (cur, new, tmp) and files (dovecot files).

Or am i literally just deleting everything within the .Trash folder including the sub folders and dovecot files? If not what command would i use to delete everything within a specific folder?

Thanks,
Mike
 

marlowmedia

Member
Oct 25, 2016
14
2
3
Wigan
cPanel Access Level
Root Administrator
@cPanelMichael I've tried to sort this by removing my email account from Outlook so that the emails are not synced back to the Trash Folder. tried running the SSH command again but it does nothing any more, then i tried changing the auto perge setting from 30days to 15 days and tried running the script and it still did nothing (no response like last time). I've left the server overnight hoping the auto perge script would work but all the emails are still in the Trash folder.

What should i do?

Thanks,
Mike
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,910
2,213
363
Hello,

Can you verify the emails exist on the server in the /home/$username/mail/$domain/$email-account/.Trash location?

Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,910
2,213
363
Hello,

Feel free to open a support ticket using the link in my signature so we can take a closer look. You can post the ticket number here so we can update this thread with the outcome.

Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,910
2,213
363
Hello,

Internal case CPANEL-12072 is open to address an issue where emails that are directly filtered to a Trash folder do not result in an added entry to the /var/cpanel/dovecot/dict.sqlite "expires" table, and thus are not removed until the email account actually manually puts an email in the Trash. I'll update this thread with more information on the status of this case as it becomes available. In the meantime, the workaround is to manually delete an email via Webmail or an IMAP-based email client to trigger the record in the /var/cpanel/dovecot/dict.sqlite "expires" table.

Thank you.