Migrating From Protonmail With Docker and Imapsync

By hernil

I’ve written about my rationale from moving away from Proton Mail. Here is how to do that using Proton Bridge, Docker and Imapsync.

Proton bridge

Protonmail does not expose standard imap interfaces for their accounts so you need to set up the Proton mail bridge to use common migration tools like Imapsync.

As Proton bridge is going to be a temporary installation I just wanted to have it in Docker for easy purging when done. Turns out someone has already dockerized it and a quick look through the project seems to show that it is a pretty bare bones wrapper for building the bridge from source. This should let us access our Proton mail account through standard Imap ports

Imapsync

Imapsync is a perl script that does what it says on the tin - it syncs mailboxes via Imap. The site looks a bit dated but that’s fine as 2 seconds of skimming will let you know that the last published version is just a few weeks old and that this is not abandonware.

Spending a few minutes actually reading the fairly comprehensive docs should get you up and running pretty fast. It also comes packaged as a Docker container which is neat for our particular use case, but it’s also packaged in what looks like most package managers out there.

Note that it is a syncing tool. That means that you will need an Imap server on the recieving end as well.

Dancing with Docker

Here is the step by step:

  • create a docker-compose.yml and link the two containers with their own internal network. Neither of them will expose ports outside this network
  • initialize the protonmail-bridge
  • fire up imapsync and let it work its magic

docker-compose.yml

version: '3.8'
networks:
  internal:
    external: false
services:
  protonmail-bridge:
    image: shenxn/protonmail-bridge
    container_name: protonbridge
    expose: # this is just for information
      - 25
      - 143
    restart: unless-stopped
    volumes:
      - ./protonmail:/root
    networks:
      - internal

  imapsync:
    image: gilleslamiral/imapsync
    container_name: imapsync
    networks:
      - internal

make sure that you have a protonmail directory next to it for this particular config.

Initialize bridge

sudo docker compose run protonmail-bridge init

Make sure to take note of your password.

After that we want the bridge to run so let’s spin it up.

sudo docker compose up

Fire up Imapsync

These settings are for Protonmail and Migadu1 spesifically on the recieving end. Tweak to you particular needs.

sudo docker compose run imapsync imapsync --skipcrossduplicates \
   --host1 protonbridge --port1 143  --user1 mailbox@example1.com --password1 'your password goes here'  \
   --host2 imap.migadu.com  --user2 mail@example2.com  --password2 'your password goes here' --port2 993 --ssl2

No that’s not a typo. We’re running the imapsync command in the imapsync container. Feel free to rename the latter in the docker-compose file if you are confused.

And that’s pretty much it. Keep an eye on the output of imapsync to see how it went and potentially rerun it with some tweaked parameters if needed. Remember the docs.


  1. pro tip: If you ask Migadu support nicely you can enable the Imap server for a domain before having changed the MX records of your DNS. This allows you to migrate emails to new mailboxes without any downtime. ↩︎


Input or feedback to this content? Reply via email!
Related Articles