Hi everyone,

I’m having a problem with my Mailcow setup. I wrote a small script that is supposed to empty the Junk and Trash folders daily via cronjob:

#!/bin/bash
cd /opt/mailcow-dockerized

# General
docker compose exec dovecot-mailcow doveadm expunge -A mailbox 'Junk' savedbefore 14d
docker-compose exec dovecot-mailcow doveadm expunge -A mailbox 'Trash' savedbefore 30d

# Service Accounts
docker-compose exec dovecot-mailcow doveadm expunge -u 'noreply-dmarc@domi-btnr.dev' mailbox % before 30d
docker-compose exec dovecot-mailcow doveadm expunge -u 'status@domi-btnr.dev' mailbox % before 30d
docker-compose exec dovecot-mailcow doveadm expunge -u 'vault@domi-btnr.dev' mailbox % before 30d
docker-compose exec dovecot-mailcow doveadm expunge -u 'nas@domi-btnr.dev' mailbox % before 30d

The problem is that it’s simply not working. My Trash folder still contains emails that are over 4 months old. When I run the doveadm expunge commands manually directly in the shell, nothing happens either.

I followed this Article: docs.mailcow.email Icon Expunge a Users mails - mailcow: dockerized documentation

Does anyone have an idea what could be causing this?

Thanks in advance for your help!

  • I tinkered a bit more with it and the issue is that I use docker-compose to run the command and not docker. Not sure why it fails with docker-compose, since I use that to start the containers. I also removed the single quotes. It looks like this now:

    # General
    # Delete JUNK/SPAM Mails older than 2 Weeks
    docker exec mailcowdockerized-dovecot-mailcow-1 doveadm expunge -A mailbox Junk savedbefore 30d
    # Delete TRASH Mails older than 30 Days
    docker exec mailcowdockerized-dovecot-mailcow-1 doveadm expunge -A mailbox Trash savedbefore 30d
    
    # Service Accounts
    # Delete all Mails older than 30 Days
    docker exec mailcowdockerized-dovecot-mailcow-1 doveadm expunge -u noreply-dmarc@domi-btnr.dev mailbox % before 30d
    docker exec mailcowdockerized-dovecot-mailcow-1 doveadm expunge -u status@domi-btnr.dev mailbox % before 30d
    docker exec mailcowdockerized-dovecot-mailcow-1 doveadm expunge -u vault@domi-btnr.dev mailbox % before 30d
    docker exec mailcowdockerized-dovecot-mailcow-1 doveadm expunge -u nas@domi-btnr.dev mailbox % before 30d

Did you check Ofelias docker logs as indicated at the bottom of the documentation?

    Have something to say?

    Join the community by quickly registering to participate in this discussion. We'd like to see you joining our great moo-community!

    esackbauer No because I use CRON and not Docker Scheduler. Are the logs still relevant when I don’t use the Docker Scheduler?

    Yes, Ofelia should still notice that expunge is working.

    I used docker logs mailcowdockerized-ofelia-mailcow-1 -f -n 0 to get the Logs and then run docker compose exec -T dovecot-mailcow doveadm expunge -A mailbox 'Junk' savedbefore 2w in a new Terminal. No logs show up

      domi-btnr
      Please run it directly from the container console, not via docker exec

        esackbauer While trying that, I realised that the Container Name was wrong. I adjusted that but still no logs.

        The command isn’t returning anything and the Ofilia Logs only return stuff for SOGO.

        That’s the Terminal Output

        admin_@mailcow:/opt/mailcow-dockerized$ docker exec -it mailcowdockerized-dovecot-mailcow-1 /bin/bashe52218e63008:/# doveadm expunge -A mailbox 'Junk' savedbefore 2w
        e52218e63008:/#

        Then I would say you should open an issue on github.

        I tinkered a bit more with it and the issue is that I use docker-compose to run the command and not docker. Not sure why it fails with docker-compose, since I use that to start the containers. I also removed the single quotes. It looks like this now:

        # General
        # Delete JUNK/SPAM Mails older than 2 Weeks
        docker exec mailcowdockerized-dovecot-mailcow-1 doveadm expunge -A mailbox Junk savedbefore 30d
        # Delete TRASH Mails older than 30 Days
        docker exec mailcowdockerized-dovecot-mailcow-1 doveadm expunge -A mailbox Trash savedbefore 30d
        
        # Service Accounts
        # Delete all Mails older than 30 Days
        docker exec mailcowdockerized-dovecot-mailcow-1 doveadm expunge -u noreply-dmarc@domi-btnr.dev mailbox % before 30d
        docker exec mailcowdockerized-dovecot-mailcow-1 doveadm expunge -u status@domi-btnr.dev mailbox % before 30d
        docker exec mailcowdockerized-dovecot-mailcow-1 doveadm expunge -u vault@domi-btnr.dev mailbox % before 30d
        docker exec mailcowdockerized-dovecot-mailcow-1 doveadm expunge -u nas@domi-btnr.dev mailbox % before 30d

          domi-btnr Not sure why it fails with docker-compose

          Maybe you have docker compose (the “native” plugin variant) and docker-compose (the standalone variant, with a dash inbetween) installed.
          You should use only one of them (the one which is mentioned in mailcow.conf), and it has to be at least version 2.0

          ETNyx Yeah that’s correct. I added the admin_ user to the docker group which allows me to run the stack as root/system but still be able to start/stop it without sudo. I don’t like having a user which has sudo perms all the time.

          Ok, i’m not developer/contributor of Mailcow, but if docs specifically mention of umask and using root that indicated it’s important to set up your access permission right, in case you are not handling your task as root but another user admin group or sudo, it’s possible you have just read permission so you are not able to expunge old mail,… Try to use root if it works or not.

          Or there is best answer now, so it’s solved?

            ETNyx Yeah it is solved. My issue was that I used the wrong Container Name and the wrong docker compose executable. But I’ll definitely check my File Permissions and Groups to see if that contributed to the Problem.

            Awesome, glad you worked it out 👍

            No one is typing