Migrating email accounts using imapsync

By Andreas Schickedanz Mar 29, 2013

Yesterday I moved my domain bornageek.com to a new Strato server. But since I hosted different mail accounts for different purposes, like one general account, one for friends and one for ebay etc., I had to migrate them to the new server. Fortunately I found imapsync, a very easy to use software that allows the user to move all emails from one account to another using the imap protocol.

To get started you have to install some packages needed by imapsync

sudo apt-get install libdate-manip-perl libterm-readkey-perl libterm-readkey-perl libdigest-hmac-perl libdigest-hmac-perl libdate-manip-perl libmail-imapclient-perl

and some packages needed to install the latest version of imapsync from the github project:

sudo apt-get install makepasswd rcs perl-doc libmail-imapclient-perl make git-core git-doc git-svn git-gui gitk

After that you could download the source code of the latest version from the github project into the /tmp directory:

cd /tmp
git clone git://github.com/imapsync/imapsync.git

Finally you could switch into the downloaded directory and install imapsync:

cd imapsync
sudo make install

You should see something like this:

Output of imapsync installation script

You are now able to move your emails from the source host to the target host using the following command:

imapsync --authmech1 LOGIN --host1 <source_hostname> -user1 <source_username> --authmech2 LOGIN --host2 <target_hostname> --user2 <target_username>

But before you actually migrate your mail accounts, you should simulate a transfere using the –dry option like this:

imapsync --authmech1 LOGIN --host1 <source_hostname> -user1 <source_username> --authmech2 LOGIN --host2 <target_hostname> --user2 <target_username> --dry

If this passes without any errors you are ready to start, but wait there are some more options you might be interested in. If you for example need to specify another port than the standard one, you could use the –port1 respectively –port2 option. Or if your servers support ssl you could enable ssl using the –ssl1 option for the source host and accordingly –ssl2 for the target host. Furthermore imapsync would ask you for the source host and target host passwords if you execute the code above, to specify the passwords directly, imapsync offers the –password1 and –password2 option. To understand how this different options work have a look at the example below.

imapsync --authmech1 LOGIN --ssl1 --host1 imap.source.tld --port1 993 -user1 web1234 --password1 ****** --authmech2 LOGIN --ssl2 --host2 imap.target.tld --port2 993 --user2 web4321 --password2 ******

Hope this helps you! Until next time, happy syncing!


is a Computer Science MSc. interested in hardware hacking, embedded Linux, compilers, etc.