Fullstack IT Nerd

Lessons learned: Email migration

Emails have become an integral part of everyday life. Many people use one of the major email providers such as Gmail or GMX. For me and my colleagues in IT, however, it is more common to register their own domain and use the email service of a provider of their choice. Some people even host their own email server.

But what do you actually do if you want to change providers or even host your own? In In contrast to moving websites and databases, there is less talk about moving email data. As I was not aware of any possible approach to migrating from provider A to provider B for a long time I didn’t dare to make the switch for a very long time.

But how do I migrate emails now?

After a long search, I came across the program imapsync by Gilles Lamiral. With this little program you can easily copy all emails from one email server to another server. server. Once you have installed the program, you can simply call it up in a terminal. Here is a small example:

./imapsync \
    --host1 imap.server1.de \
    --user1 username1 \
    --password1 "password1" \
    --host2 imap.server2.de \
    --user2 username2 \
    --password2 "password2"

You can find more examples and instructions on the program’s website. If you use the program frequently, should consider thanking the author for his efforts and buying a license for the program.

What else can you do with the program?

I also use imapsync to back up my emails. With the help of a Docker container you can set up a local IMAP server and back up your emails to the local server. The following call can be used to start the container:

docker run --rm \
    --publish 127.0.0.1:143:143 \
    --volume [Pfad]:/srv/mail \
    --name imap dovecot/dovecot

The backup can then be started with the following call:

./imapsync \
    --host1 [Email Server] \
    --user1 [Username] \
    --password1 [Password] \
    --host2 localhost \
    --user2 backup \
    --password2 pass \
    --delete2

Alternatives

You can also use many other tools to back up your IMAP account. I have also already had good experiences with imap-backup.

Miscellaneous
Github | Mastodon | BlueSky | LinkedIn | Status