How to transfer email accounts with imapsync

Updated on Apr 23, 2018

This tutorial is meant to help the more advanced users with synchronizing two email mailboxed by using the flexible and robust command imapsync. This can be also used to transfer your mail accounts between your new hosting account and your previous provider. If you are not familiar with the Linux terminal you can look up our beginner tutorial series.

Firstly you will need to have access to the following:

  • IMAP access to both the source and destination's (gmail , yahoo, etc.) email servers
  • You will need SSH access to execute the command.


In case you are about to transfer your emails from another hosting provider you will need to create your email accounts on your new host prior initiating the transfer. If your new hosting account is currently hosted with FastComet, we offer free email migration on all hosting plans.

The simplest form of the command is like this:

imapsync --host1 <host_sync_from> --ssl1 --user1 < [email protected] > --host2 <host_sync_to> --ssl2 --user2 < [email protected] >

Now for a dissection of what each field of the code above means.

--host1 <host_sync_from> - specifies the host name from where you want to synchronize mailbox(e.g.

--ssl1- informs that the connection that is established with --host1 must be over SSL

--user1 <[email protected]>- the email username of --host1 from which you want to sync

--host2 <host_sync_to>- same as for --host1, but this time it specifies the destination to where you want to sync (e.g.; this is --host2)

--ssl2- informs that the connection that is established with --host2 must be over SSL

--user2 <[email protected]>- same case as with --user1, only here the destination email user is required

After executing you will be prompted to enter the passwords of the two users, first the user from which you want to sync then the user to which you want to sync.

An example of the command with actual parameters:

imapsync --host1 --ssl1 --user1 [email protected]  --host2 --ssl2 --user2  [email protected]


A big advantage of the imapsync command is that you can run it multiple times and each run will start from where the last run finished. This may come in handy if there is a large amount of messages that you want to synchronize. However, if you happen to use this method don't sort, delete or modify the messages in the destination mailbox, as this might cause the messages to be synchronized again.

There are also some more advanced options if you would like to further configure the imapsync command to your liking. Here are a few of the more notable mentions that you might want to include in the command:

--tls1 and --tls2 flags- these flags specify that the connection to --host1 and --host2 respectively should be over TLS encryption protocol. You might also have to use this flag if one of the servers supports only TLS connection.

--authmech1 <string> and --authmech2 <string>- this command option specifies the authentication mechanism that should be used when connecting to --host1 and --host2 respectively. In the <string> you enter the authentication method; e.g. PLAIN which the simplest authentication method. With this authentication method the username and password are send without any kind of encryption to the server(you might also have to use this flag if one of the servers supports only PLAIN authentication).

--dry- if you use the --dry flag, when you execute the command it will instead present you with data on what will actually happen if you execute the command. This may come in handy if you are uncertain what you actually want to be synchronized.


If you wish to skip the input of the passwords you can surely use the --password1 and --password2 flags but it is more advisable to store the passwords in files and use the --passfile1 and --passfile2 flags

--exclude <regex> - this flag excludes the specified <regex> folder(s) , where <regex> is a regular expression (e.g. --exclude ‘^Trash\ E-Mail' ). This is useful if there is a particular folder which you don't want to transfer.

On this page...

    SSD Web Hosting

    • Free Domain Transfer
    • 24/7 Technical Support
    • Fast SSD Storage
    • Hack-free Protection
    • Free Script Installation
    • Free Website Transfer
    • Free Cloudflare CDN
    • Immediate Activation
    View More