Skip to main content

Automatic deletion of emails with cron

Comments

5 comments

  • cPanelLauren
    Hi @iorbita Looking at that command it does indicate the specific folder that you'd be targeting: /home/SERVER_LOGIN_USERNAME/mail/DOMAIN_NAME/MAIL_ACCOUNT_NAME/cur
    It's removing mail from cur. You can change that to any one of the folders that are present in the mail directory for the domain for example: find /home/%user/mail/example.com/mailuser/new -type f -mtime +90 -exec rm {} \;
    This would remove all mail older than 90 days in /home/$user/mail/example.com/mailuser/new Thanks!
    0
  • iorbita
    ... thank you very much for your reply! ;)
    0
  • cPanelLauren
    Hi @iorbita You're very welcome, I'm glad I could help!
    0
  • spinge
    I don't know how to do with a specific subject, but here is the solution to delete Inbox emails older than the last 90 days on a daily rotating basis, and get Cpanel to also update your mailbox size (This does not happen automatically after just deleting the emails). Assumption: Let's assume that your email is EMAILNAME@DOMAIN.COM and your cpanel account is CPANELACCOUNTNAME Solution: Go to Cpanel > Advanced > Cron Jobs > Add New Cron Job > a. Common Settings: Once Per Day (0 0 * * *) b. Command: find /home/CPANELACCOUNTNAME/mail/DOMAIN.COM/EMAILNAME/ -type d \( -name cur -o -name new \) -exec find {} -mtime +90 -type f -delete \; -o -name maildirsize -delete
    c. Click on 'Add new Cron Job'. Done! --- Similarly, to delete Trash emails older than 7 days on a daily rotating basis for the same user: Solution: Go to Cpanel > Advanced > Cron Jobs > Add New Cron Job > a. Common Settings: Once Per Day (0 0 * * *) b. Command: find /home/CPANELACCOUNTNAME/mail/DOMAIN.COM/EMAILNAME/.Trash/ -type d \( -name cur -o -name new \) -exec find {} -mtime +7 -type f -delete \;
    c. Click on 'Add new Cron Job'. Done! --- Note: mtime +90 = 90 days mtime +7 = 7 days Folder names and location for your reference: Inbox = /home/CPANELACCOUNTNAME/mail/DOMAIN.COM/EMAILNAME/ Trash = /home/CPANELACCOUNTNAME/mail/DOMAIN.COM/EMAILNAME/.Trash/ Spam = /home/CPANELACCOUNTNAME/mail/DOMAIN.COM/EMAILNAME/.spam/ Junk = /home/CPANELACCOUNTNAME/mail/DOMAIN.COM/EMAILNAME/.Junk/ Sent = /home/CPANELACCOUNTNAME/mail/DOMAIN.COM/EMAILNAME/.Sent/ Draft = /home/CPANELACCOUNTNAME/mail/DOMAIN.COM/EMAILNAME/.Draft/
    0
  • iorbita
    ... thank you Spinge for your participation in this discussion thread ;)
    0

Please sign in to leave a comment.