Auto-deletion of emails

cag8f

Member
Jul 25, 2014
10
0
1
cPanel Access Level
Website Owner
Hi all. New cpanel user and first post here.

Is there a method built-in to cpanel that can auto-delete my emails after X days? Or is this something I would have to create a CRON job to carry out?

Thanks in advance.
 

cPanelMichael

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

Note that if you want the "Trash" email automatically deleted, you can browse to:

"WHM Home » Service Configuration » Mailserver Configuration"

There is an option titled "Auto Expunge Trash" if you are using Dovecot, or an option called "IMAP Empty Trash" if you are using Courier.

Thank you.
 
  • Like
Reactions: Tamer Fahmy

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,218
463
You can edit the following file for local modifications to the Dovecot configuration:

Code:
/var/cpanel/templates/dovecot2.2/main.local
Note: You can copy this file from /var/cpanel/templates/dovecot2.2/main.default if it does not exist. The relevant section here is:

Code:
[% IF expire_trash %]
  expire_dict = proxy::expire
  expire = Trash
  expire2 = "Deleted Messages"
  expire3 = "INBOX.Deleted Messages"
  expire4 = INBOX.Trash
You can add additional mailbox names to this section (e.g. Junk). After making the custom modifications, you must run:

Code:
/scripts/builddovecotconf
Thank you.
 

marcochiesi

Member
Mar 1, 2011
24
1
53
Italy
cPanel Access Level
Root Administrator
Twitter
Hi Michael,
thanks a lot for your reply, it was exactly what I was looking for.... unfortunately I was not able to let it work.
As you suggested I made a copy of /var/cpanel/templates/dovecot2.2/main.default to /var/cpanel/templates/dovecot2.2/main.local and I made the following changes:
Code:
[% IF expire_trash %]
  expire_dict = proxy::expire
  expire = Trash
  expire2 = "Deleted Messages"
  expire3 = "INBOX.Deleted Messages"
  expire4 = INBOX.Trash
  expire5 = Junk
  expire6 = Spam
  expire7 = spam
  expire8 = INBOX.Junk
  expire9 = INBOX.Spam
  expire10 = INBOX.spam

[% END %]
Then I run
Code:
/scripts/builddovecotconf
which had the following output
Code:
info [builddovecotconf] 'local' template in use (/var/cpanel/templates/dovecot2.2/main.local)
I suppose there's a cPanel nightly task that calls this procedure, but it did not delete old spam messages last night.
I also tried to manually run
Code:
/scripts/maintenance
which had this in its log
Code:
...
[20141002.091305]   Processing: Cleaning up mailbox trash
[20141002.091305]    - Processing command `/usr/local/cpanel/scripts/dovecot_auto_expunge_trash`
...
but spam messages are still there.

By the way, inside the dovecot config file a comment says:
Code:
  # Expire plugin. Mails are expunged from mailboxes after being there the
  # configurable time. The first expiration date for each mailbox is stored in
  # a dictionary so it can be quickly determined which mailboxes contain
  # expired mails. The actual expunging is done in a nightly cronjob, which
  # you must set up:
  #   dovecot --exec-mail ext /usr/libexec/dovecot/expire-tool
but if I try to run
Code:
dovecot --exec-mail ext /usr/libexec/dovecot/expire-tool
I get
Code:
Fatal: Unknown argument: --exec-mail
I suppose it was for an old dovecot version.

Any ideas?
 
Last edited:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,218
463
Do you notice any output when running "/scripts/dovecot_maintenance" directly? Have you moved new email to the Trash or SPAM directories since making the change and has it passed the expire time?

Thank you.
 
Last edited:

marcochiesi

Member
Mar 1, 2011
24
1
53
Italy
cPanel Access Level
Root Administrator
Twitter
The "/scripts/dovecot_auto_expunge_trash" gives no output, but your words made me think... Many old messages were recently moved to Trash/Spam folders. I thought they would have been deleted since they were pretty old, but it makes sense that the 30 days are counted starting from the date of deletion and not from the date of the message. So I suppose they will be deleted in a month or so.
By the way, is there a way to get the deletion date of a message?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,218
463
You could try finding the individual email via the command line and using the "stat" command to see when it was last accessed.

Thank you.
 

mcpacific

Member
May 3, 2015
16
1
53
Los Angeles, CA
cPanel Access Level
Root Administrator
I have been having problems with this myself. Under WHM » Service Configuration » Mailserver Configuration I have set Auto Expunge Trash [checked] and set Trash Expire Time to be 10. Also, my dovecot.conf file includes the following:

Code:
  expire_dict = proxy::expire
  expire = Trash
  expire2 = "Deleted Messages"
  expire3 = "INBOX.Deleted Messages"
  expire4 = INBOX.Trash
  expire5 = Junk
  expire6 = INBOX.Junk
Yet, Trash and Junk never auto expunge. I ran the following script manually, however, and it cleaned one of my Trash folders on one email account (the Junk folder was NOT auto expunged):

Code:
/scripts/dovecot_auto_expunge_trash
Other than checking the setting in Mailserver Configuration, do I need to manually add a cron job? What do I do about the Junk folders? I'm using WHM 11.48.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,218
463
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.
 

Mckenzielaa

Member
Jul 10, 2014
13
5
3
cPanel Access Level
Root Administrator
Hi @cPanelMichael ,

I have followed the steps in an old thread to auto delete the spam messages that Spamassassin marks as spam and places in the Junk folder, the thread is at Auto-deletion of emails but they do not work.

I created the copied the file /var/cpanel/templates/dovecot2.2/main.default to /var/cpanel/templates/dovecot2.2/mail.local

I added the expire 4, 5 and 6

[% IF expire_trash %]
expire_dict = proxy::expire
expire = Trash
expire2 = "Deleted Messages"
expire3 = "INBOX.Deleted Messages"
expire4 = INBOX.Trash
expire5 = Junk
expire6 = INBOX.Junk

I then rebuilt the config, and get the
'local' template in use message (/scripts/builddovecotconf) but when I run
dovecot --exec-mail ext /usr/libexec/dovecot/expire-tool command I get

Fatal: Unknown argument: --exec-mail error. When I try running /scripts/dovecot_auto_expunge_trash directly I get a
-bash: /scripts/dovecot_auto_expunge_trash: No such file or directory error.

Did you ever manage to get this working as I see you asked for the other person who asked about this to submit a ticket but no update was made to the thread
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,218
463
Hello @Mckenzielaa,

The functionality of the auto_expunge_trash script was merged into /scripts/dovecot_maintenance in cPanel & WHM version 58.

Can you verify if running /scripts/dovecot_maintenance removes the messages that are older than what you've set for the Trash Expire Time value?

Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,218
463
Hello @Mckenzielaa,

Can you open a support ticket so we can take a closer look at your system to see how you've configured Dovecot and to verify that it's not working as intended? You can post the ticket number here and I'll link this thread to it.

Thank you.