I was stuck with an older version of mailcow from 2017 which was not upgradeable via update.sh, and if you are too you can follow this steps to solve it.

Please create a Backup of your mailcow server first. If you cann not access the interface but have access to the server via a terminal you can also only save/migrate the email-volume in /var/lib/docker/volumes/mailcowdockerized_vmail-vol-1

 

rsync -aHhP --numeric-ids --delete /var/lib/docker/volumes/mailcowdockerized_vmail-vol-1/_data/ root@host:/var/lib/docker/volumes/mailcowdockerized_vmail-vol-1/_data

 

  • use the importer.sh script to import all emails to the corresponding email-address directly in the container:

 

#!/bin/bash

# Define the parent path of the Maildir
MAILDIR_PARENT="/var/vmail"

# Get all users from doveadm
USERS=$(doveadm user '*')

# Loop through each user
for FULL_USER in $USERS; do
    # Extract domain and username
    DOMAIN=$(echo "$FULL_USER" | cut -d@ -f2)
    USER=$(echo "$FULL_USER" | cut -d@ -f1)

    # Construct the path to the user's Maildir
    USER_MAILDIR="${MAILDIR_PARENT}/${DOMAIN}/${USER}"

    # Check if the Maildir exists
    if [ -d "$USER_MAILDIR" ]; then
        echo "Processing $USER_MAILDIR"

        # Insert your command to import mails from the user's Maildir
        # For example, using doveadm import (adjust as necessary):
        doveadm import -u $FULL_USER maildir:$USER_MAILDIR "" all

        # Replace the above line with your actual command for importing mails.
    else
        echo "Maildir not found for $FULL_USER"
    fi
done

I made a Github repo, so you can download the importer script here: https://github.com/gweit/mailcow-importer

This should also work for non-mailcow installations, as long as the folder structure is dovecot-like.

Feel free to reach out if you need some help: [email protected]