Skip to content

How to Migrate from VMM to Mailu

Lets' take an example domain, to write the docs as-we-go: example.com.

1. DNS operations

First, you need to make sure that:

  • no emails flow via Mailu (sometimes it was configured as secondary MX)
  • DNS TTLs are low enough that on migration day you are not bothered by timeouts.

In other words:

  • delete any MX records that are not at the highest priority and that point to mail.raksha.ch
  • reduce the TTL for all MX records to 5 minutes (or 1h on desec.io)

The result should be something like:

$ dig +short MX example.com          
10 mail.flosstools.org.

2. Check the domain requirements

  1. Login to phoenix and get a shell in the email container:
  2. Execute the following commands to get an idea of the amount of emails ans aliases you'll need:
vmm domaininfo example.com

3. Domain creation on mailu

  1. Head to https://mail.raksha.ch/admin/domain and login as postmaster@mail.raksha.ch
  2. Hit "New Domain" and fill in your numbers
  3. don't bother for the quota just now
  4. do not tick "authorize registration"
  5. fill in a useful comment (such as Swisslinux.org (OdyX))

4. Aliases creation on mailu

  1. Run that command in the 'email' container:
DOMAIN=example.com
for alias in $(vmm listaliases $DOMAIN | grep '[+]' | sed -e 's/.*] //g' | grep -v 'postmaster@'); do localpart=$(echo "$alias" | cut -f1 -d@); domain=$(echo "$alias" | cut -f2 -d@); dests=""; for dest in $(vmm aliasinfo $alias | grep ' \* ' | sed -e 's/.* \* //g'); do dests="$dests,$dest"; done; dests=$(echo "$dests"| cut -c 2-); echo "INSERT INTO \"alias\" (localpart,domain_name,email,destination,created_at) VALUES ('$localpart','$domain','$alias','$dests',now());"; done
echo "INSERT INTO \"alias\" (localpart,domain_name,email,destination,created_at) VALUES ('postmaster', '$DOMAIN', 'postmaster@$DOMAIN', 'postmaster+$DOMAIN@mail.raksha.ch',now());"

That gives you a series of 'INSERT INTO' SQL commands.

  1. Get a PSQL shell (from the phoenix shell)
lxc exec mailu -- sudo -u mailu bash -c 'cd /srv/mailu; docker-compose exec db psql -h localhost -U mailu mailu'
  1. Paste the INSERT INTO stances in that psql shell; verify from the interface that the aliases make sense.

5. Migrate the actual email accounts

For each email account of the domain, do:

  1. Create the email account from the mailu (mail.raksha.ch) interface
  2. From the mailu container, run the synchronization script:
lxc exec mailu /root/sync_from_email.sh emailaddress@example.com
  1. Add that command to the root user on the mailu container of phoenix, with an hourly frequency
@hourly /root/sync_from_email.sh emailaddress@example.com
Mailu puller script
#!/bin/sh

set -e

EMAIL=$1

if [ -z "$EMAIL" ]; then
        >&2 echo "Email is empty. Abort";
        exit 1;
fi

# Get folder from email container
vmmdir=`ssh root@email vmm userinfo $EMAIL | grep Home | sed -e 's/^.*: //g;s|/$||g'`

# Check that the directory exists
ssh root@email test -d $vmmdir/Maildir

rsync -avz --no-perms --chown mail:man root@email:$vmmdir/Maildir/ /srv/mailu/mail/$EMAIL

chown mail:man /srv/mailu/mail/$EMAIL

if ssh root@email test -d $vmmdir/sieve; then
  rsync -avz --no-perms --chown mail:man root@email:$vmmdir/sieve /srv/mailu/mail/$EMAIL/
fi

6. Inform your users, and give them time to check and test, announce a flag day

TODO: better explanation of what changes for users (from mail.flosstools.org to mail.raksha.ch, etc).

7. Actual migration

  1. Run a sync for the actual users
  2. Toggle the DNS records to mail.raksha.ch
  3. Wait for the propagation time (TTL * 2)
  4. On on the mail container:
  5. Backup the whole domain emails bash dir=$(vmm domaininfo $DOMAIN | grep "Domain Directory" | sed -e 's/.*: //g'); tar cvzf /root/$DOMAIN.tar.gz $dir
  6. Delete the email domain bash vmm domaindelete $DOMAIN force
  7. Mark the domain as relayed to Mailu
    1. edit /etc/postfix/transports/mailu_domains to add a line for $DOMAIN
    2. run postmap /etc/postfix/transports/mailu_domains to compile the file and reload postfix
  8. Add mail.flosstools.org as secondary MX (higher priority) in $DOMAIN's DNS

Done. Enjoy.