How to Migrate Emails Using imapsync?

Posted on October 24th, 2018

How to Migrate Emails Using imapsync?


What is imapsync?

Imapsync is a method used in website migration. Imapsync copies mailboxes from one server to another during migration. For performing imapsync, the email accounts should use IMAP protocol instead of POP3. Imapsync is a good tool for copying mailboxes because it will not transfer emails which is present on both servers. And also preserves the flags read, sent, unread. That means read will stay read, unread will stay unread, deleted will stay deleted on the new server. To perform imapsync during migration we need to know the following details:

1) IMAP server name at old hosting.

2) Create all the email accounts under new host and

3) List the details of email accounts in the following format

“oldusername” “oldpassword” “newusername” “newpassword”



IMAP is a standard email protocol and it stands for Internet Message Access Protocol. IMAP stores email messages on a mail server but allow the end user to view and manipulate the messages as though they were stored locally on the end user’s computing device(s).



POP3 stands for Post Office Protocol. It is another protocol used to access emails. POP3 downloads email from a server to a single computer then deletes it from the server.


1)  Install imapsync

To install imapsync on CentOS you will need to follow the below-given steps.

IMAP sync is written in Perl and is open source, so imapsync isn’t in any of the official CentOS repositories. So at first, we need to install the epel repository.

To install the epel repository follow the below steps:

$ wget

$ wget

$ rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm

After installing epel repository, install imapsync using the yum command.

$ yum install imapsync

Now imapsync is installed and now we can proceed with the migration of mailboxes.


2) Migration.

We can access an IMAP account with three parameters. The parameters are;

1) The imap server host. It’s a server name or an ip address

2) The username

3) The password

Since the imapsync job is to sync two imap accounts we need to know both server’s hostname, username, and password for proceeding with the syncing. The basic command format for imapsync is

/usr/bin/imapsync \

–host1 –user1 [email protected] –password1 mypasswd \

–host2 –user2 [email protected] –password2 mypasswd

Here we use the –password1 and –password2 switches for the passwords, but this is not a secure way because the passwords would appear in the output of ps -aux. So for ensuring security, we will create two files that contain password and change the permission of the files to 600. After creating the files, we can use the switches –passfile1 and –passfile2 instead of the –password1 and –password2.

Now we can do the migration with the below command:

imapsync –host1 –user1 [email protected] –passfile1 /file name of passwords –host2 –user2 [email protected] –passfile2 /file name of passwords

After imapsync, we can delete the two password files.

On the target server log out of your IMAP account and log back in and you should see the messages from the source server. Because a simple refresh sometimes might not be enough.


If you need any further assistance please contact our support department.



7 Responses to “How to Migrate Emails Using imapsync?”

  1. William Lima says:


  2. Anonymous says:

    How secure is imapsync? Is a free tool?
    Does it store a copy of the email online, or locally in their server.

  3. Keith says:

    Can I spin up a VPS here with imapsync already installed and ready to go?

    • NAGENDRA says:


      When you get a VPS it doesn’t come with any control panel. So you need to get a control panel installed like cPanel, DirectAdmin, or Webuzo. And yes we can help you with imapsync.


      • Keith says:

        I already have hosting with you guys and have a cPanel, how do I add imapsync to it?

        • Bibin Varghese says:

          If it’s from Gsuite, you can use below command:

          # screen -S mail_migration
          # imapsync –host1 –port1 993 –ssl1 –user1 [email protected] –passfile1 /etc/secret1 –host2 –port2 993 –ssl2 –user2 [email protected] –passfile2 /etc/secret2>

          For more details, you can Live Chat with us from the home page or send mail to support[at]interserver[dot]net

Leave a Reply