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 a shell on the estafette.ik.vps.flosstools.org VPS)
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 email container, push the directory of your user
USER=kevin@ohsystems.io; dir=$(vmm userinfo $USER | grep "Home..." | sed -e 's/^.*: //g;s|/$||g'); rsync --rsh="ssh -i /root/.ssh/id_rsa_email -l debian" -avz $dir/ estafette.ik.vps.flosstools.org:mails-from-phoenix/$USER
  1. From the estafette.ik.vps.flosstools.org VPS, sync the emails to the mailu directory
export USER=kevin@ohsystems.io
sudo rsync -avz --no-perms --chown mail:man /home/debian/mails-from-phoenix/$USER/Maildir/ /srv/mailu/mail/$USER
  1. From estafette.…, also sync the sieve scripts, if they exist:
export USER=kevin@ohsystems.io
if test -d /home/debian/mails-from-phoenix/$USER/sieve; then
  sudo rsync -avz --no-perms --chown mail:man /home/debian/mails-from-phoenix/$USER/sieve /srv/mailu/mail/$USER/
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.