Skip to content

Instantly share code, notes, and snippets.

@pmdevita
Last active January 28, 2024 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmdevita/07d505e138bbccf1ecbafb8bb63e09f6 to your computer and use it in GitHub Desktop.
Save pmdevita/07d505e138bbccf1ecbafb8bb63e09f6 to your computer and use it in GitHub Desktop.
Migrate iRedMail to Mailcow

Migrate iRedMail to Mailcow

I've been eyeing Mailcow for a while since it's use of Docker should ease the maintenance and update burden (you iRedMail users know what I'm talking about lol) and bring a better UI and user experience with it's admin panel. Here are some notes that I took from my migration in case it helps anyone else out.

I setup a Mailcow instance on another server so I could keep iRedMail operating during the migration. After it was completed, I used Mailcow's backup and restore feature to move it to my original server.

Migrating has three main parts, mail, contacts and calendars, and DKIM. There's also some configuration which I'll touch on too.

Migrating User Data

Mail

Prior to this, you should have added your email domain to Mailcow in order to setup the accounts.

Mailcow comes with a tool for syncing over a mailbox through IMAP. It looked like there might be some way to migrate with a Dovecot command but this just ended up being simpler.

For every single user, add an account for them on Mailcow. Then, reset their password on iRedAdmin (or just use the current password if you have it) and add a sync rule for them with it. It takes a few minutes to sync so you can let this run while you take care of the next steps.

Contacts/Calendar (SOGO profile)

Prior to this, you need to have an account in Mailcow for every user you are migrating over.

SOGo also has it's own migration tool. On the iRedMail server, run

su - sogo -s '/bin/bash' -c '/usr/sbin/sogo-tool backup /tmp/sogobkup email@example.com'

for every single user. This will collect all of their user data in a folder in /tmp/sogo/.

After this, we need to copy their data into the SOGo Mailcow Docker container. It's easiest to just put it in data/conf/sogo, which will be /opt/mailcow-dockerized/data/conf/sogo for most of you. Note that you need to move the folder, so the final path should be /opt/mailcow-dockerized/data/conf/sogo/sogobkup.

Next, open a shell inside the SOGo container with sudo docker compose exec sogo-mailcow /bin/bash, then su -s /bin/bash sogo to swap to the SOGo user.

Finally, to restore run /usr/sbin/sogo-tool restore -f ALL /etc/sogo/sogobkup email@example.com for each user.

DKIM

Prior to this, you need each of your mail domains added to Mailcow.

Thie one's the easiest. It's best to just adopt your current DKIM keys so you don't have to change your DNS records. To add each key, go to the Mailcow admin configuation page, go to Configuration -> ARC/DKIM keys -> Import private key. I don't remember if DKIM key location was standardized, but mine were in /var/lib/dkim on the iRedMail server. You can just cat the contents of each key and copy it into the Mailcow UI.

After this, your Mailcow instance should be good to move over!

Configuration

Configuration is going to be more individual, so I'll just link a few things that helped me.

I put Mailcow behind an Nginx reverse-proxy, the docs for that are here https://docs.mailcow.email/post_installation/firststeps-rp/#nginx

Mailcow's LetsEncrypt was too much of a headache to work with so I ended up just acquiring the keys myself with certbot on the host. This issue on Mailcow should provide some help. I'll also post an example override too.

Finally, I used another server to host a ClamAV server. Here's another helpful issue. I setup a VPN between the two servers using tinc using this guide as a reference. I also used this Docker image. You might have to open the port to the VPN if you are using UFW, the command I used was sudo ufw allow in on tun0 to any port 3310.

version: '2.1'
services:
dovecot-mailcow:
volumes:
- ./data/assets/ssl:/etc/ssl/mail/:rw
- /etc/letsencrypt/live/example.com/fullchain.pem:/etc/ssl/mail/cert.pem:ro
- /etc/letsencrypt/live/example.com/privkey.pem:/etc/ssl/mail/key.pem:ro
- /etc/letsencrypt/ssl-dhparams.pem:/etc/ssl/mail/dhparams.pem:ro
postfix-mailcow:
volumes:
- ./data/assets/ssl:/etc/ssl/mail/:rw
- /etc/letsencrypt/live/example.com/fullchain.pem:/etc/ssl/mail/cert.pem:ro
- /etc/letsencrypt/live/example.com/privkey.pem:/etc/ssl/mail/key.pem:ro
- /etc/letsencrypt/ssl-dhparams.pem:/etc/ssl/mail/dhparams.pem:ro
watchdog-mailcow:
volumes:
- ./data/assets/ssl:/etc/ssl/mail/:rw
- /etc/letsencrypt/live/example.com/fullchain.pem:/etc/ssl/mail/cert.pem:ro
- /etc/letsencrypt/live/example.com/privkey.pem:/etc/ssl/mail/key.pem:ro
- /etc/letsencrypt/ssl-dhparams.pem:/etc/ssl/mail/dhparams.pem:ro
nginx-mailcow:
volumes:
- ./data/assets/ssl:/etc/ssl/mail/:rw
- /etc/letsencrypt/live/example.com/fullchain.pem:/etc/ssl/mail/cert.pem:ro
- /etc/letsencrypt/live/example.com/privkey.pem:/etc/ssl/mail/key.pem:ro
- /etc/letsencrypt/ssl-dhparams.pem:/etc/ssl/mail/dhparams.pem:ro
@gmpreussner
Copy link

Just wanted to say thank you - this saved me a lot of time today! <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment