How to migrate emails between 2 servers using IMAPSYNC Matt B, May 2, 2024 Table of Contents IntroWhat is IMAPSYNC?Using DockerPull the IMAPSYNC Docker imageConfigure the parametersRun IMAPSYNCVerify it’s workingWrapping upIntroWhen moving email hosting to another provider, you might want to migrate emails between 2 servers. If you need to migrate emails between 2 email servers that both support IMAP, IMAPSYNC is a great option. This tool will allow you to quickly and easily move all of the folders, while retaining all of the metadata for the email messages.What is IMAPSYNC?IMAPSYNC is a powerful command-line tool designed for synchronizing or migrating mailboxes between IMAP servers. It preserves message flags, folder structure, and even the read/unread status of emails. As it’s incredibly easy to use, it’s been my go-to tool for migrating emails for years, and I’ve moved hundreds of gigabytes with it. IMAPSYNC is available in a range of formats, including:A docker imageAn online versionAn installable command line utilityIf I’m doing a small migration, I typically use the online version. This is because it provides a really clear UI to see what is happening:However, if you’re looking to migrate many, many gigabytes of email, using Docker can be a better option as it runs on your local machine rather than the always available but sometimes slow IMAPSYNC-provided one.Using DockerDocker provides a convenient way to use IMAPSYNC quickly and easily, and most importantly with great speed. Using Docker is also great because you can run the entire process in one container, which is then automatically removed afterwards. This means that if you keep the image installed locally, you can use it again and again without taking up lots of disk space, as you won’t have old containers lingering around.Pull the IMAPSYNC Docker imageIf you haven’t already done so, make sure Docker is installed on your machine. There are many guides out there showcasing how to do this for Windows, Linux and Mac. Once it’s installed, pull down the Docker image by running the following command:docker pull gilleslamiral/imapsyncThis will pull down the image to your machine, which means we can then run it later.Configure the parametersIMAPSYNC has a number of parameters available. Some of these are optional, however a number of them are required. This is because they provide key information that is needed, such as the credentials used to authenticate the IMAP accounts. I typically configure the parameters in a text editor first before pasting this into my console. Below is an example of what you might use to move emails without any additional settings.docker run --rm -it gilleslamiral/imapsync imapsync --host1 SOURCE_SERVER --user1 SOURCE_USERNAME --password1 SOURCE_PASSWORD --host2 DESTINATION_SERVER --user2 DESTINATION_USERNAME --password2 DESTINATION_PASSWORD --dryThis command when executed will run IMAPSYNC, and authenticate against the 2 hosts I specify with the usernames (email addresses) and passwords I specify. Although, crucially, I am using the –-dry parameter which will allow me to see what would happen, without it happening. When you want to actually move the emails, make sure that you remove this parameter.More information on of all of the available parameters can be found on the website of Giles Lamiral, who developed IMAPSYNC.Run IMAPSYNCPaste your command from Step 2 into your terminal and run it. You should start seeing output that suggests emails are moving:You may however run into some authentication errors. If this happens, double-check your parameters, and also consider things such as 2FA or Google’s “less secure app access”. IMAPSYNC should let you know which host has failed to connect, allowing you to troubleshoot this easily.Verify it’s workingOpen the destination host and begin refreshing. If your emails are being migrated successfully, you should start seeing them appearing on the destination server. In our example, we’ve setup 2 dummy accounts, alice and bob. Alice has got one email, Bob has none. Using IMAPSYNC, we’ve cloned the email from Alice to Bob.Before:After:Wrapping upThis guide has shown you how to use IMAPSYNC and Docker to migrate emails between 2 IMAP-supported email servers. If you’ve got any questions or run into any problems, please feel free to leave a comment. Email