Using Imapsync to import email accounts from one server to another: I provide Web hosting services using Ispconfig. For quite sometime, it was a real pain to migrate existing Cpanel customers to Ispconfig, especially when you’re required to import all users’ Mailboxes and data. I had to manually import Dovecot Mailbox folders between the two servers.

This was boring and tedious manual process. Fortunately, I did discover a nice tool called imapsync which automates this process of mail syncing between servers. This can work on any setup, It doesn’t have to be Cpanel-Ispconfig relationship. All you need is two Mail servers with IMAP. Let’s dive deep to using Imapsync.

using Imapsync: Prerequisites

  • Have a FQDN – Both has to be same on server A and B. In my case, on Ispconfig and Cpanel
  • Working IMAP service on both servers
  • If on Shared Hosting, make sure you know the IP address of the server hosting your web content
  • You should know usernames and passwords for the source email accounts and destination

Installing imapsync

Before using Imapsync , you’ll definitely need to install first.

Install imapsync on Debian and Ubuntu

1. First install required dependency packages:

sudo apt-get install   \
liburi-perl             \
make                    \
libauthen-ntlm-perl \
libcrypt-ssleay-perl \
libdigest-hmac-perl  \
libfile-copy-recursive-perl \
libio-compress-perl \
libio-socket-inet6-perl \
libio-socket-ssl-perl   \
libio-tee-perl          \
libmail-imapclient-perl \
libmodule-scandeps-perl \
libnet-ssleay-perl      \
libpar-packer-perl      \
libreadonly-perl        \
libterm-readkey-perl    \
libtest-pod-perl        \
libtest-simple-perl     \
libunicode-string-perl  \

2. Then manually install perl module Data::Uniqid and Mail::IMAPClient

# cpanm Data::Uniqid Mail::IMAPClient

3. Now download imapsync tarball and install it.

Check for the latest here:

cd /usr/local/src
tar zxvf tar zxvf imapsync*
cd imapsync-imapsync*

Do a dependencies test that shows also the basic example:


A live test showing imapsync job:

 ./imapsync --testslive

Now the install command (need root priviledges again):

# cp imapsync /usr/bin/

Now go to read start with the tutorial.

Install imapsync on CentOS/RHEL

# yum -y install epel-release
# yum -y install imapsync

Installation reference:

Imapsync usage syntax:
imapsync --host1 \
 --user1 [email protected] --password1 secret1 \
 --host2 \
 --user2 [email protected] --password2 secret2 and can be replaced with appropriate IP addresses.

using Imapsync: Migrating Email accounts

using Imapsync needs creation of a file with usernames and passwords like below:

# vim $HOME/accounts.txt

Add Mailbox accounts with passwords.

  • Each line contains 6 columns, columns are parameter values for –host1 –user1 –password1 –host2 –user2 –password2
  • Separator is character semi-colon “;” it can be changed by any character changing IFS=‘;’ in the while loop below.

The add this script:

cat > $HOME/<<EOF
echo "Looping on account credentials found in accounts.txt"
echo ""
{ while IFS=';' read  h1 u1 p1 h2 u2 p2 fake
        { echo "$h1" | egrep "^#" ; } > /dev/null && continue # this skip commented lines in accounts.txt
        echo "==== Starting imapsync from host1 $h1 user1 $u1 to host2 $h2 user2 $u2 ===="
        imapsync --host1 "$h1" --user1 "$u1" --password1 "$p1" \
                 --host2 "$h2" --user2 "$u2" --password2 "$p2" \
                 "[email protected]"  
        echo "==== Ended imapsync from host1 $h1 user1 $u1 to host2 $h2 user2 $u2 ===="
} < $HOME/accounts.txt

You can proceed to using Imapsync script and wait for IMAP Mail sync to finish.

# bash $HOME/

This will sync emails from host1 to host2 and will give you real time progress about the transfer.

If you encounter network connection problems or timeout, just run the script again and it will pick up where it left.

To this point, we’ve covered important essentials on using Imapsync to sync mail accounts between two servers. This can be applied to any Mail server- Mostly Open source mail solutions.

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.


Please enter your comment!
Please enter your name here