How to Migrate Mails with IMAP Sync on CentOS 8 / Ubuntu 20.04

Migrate Mails with IMAP Sync

imapsync is an IMAP transfer tool and is used to migrate emails from one IMAP server to another IMAP server. imapsync is a Linux package that can be downloaded from the repository on CentOS. But we need to use the git repository to download the Ubuntu distribution. In this tutorial, we will learn how to migrate Mails and use IMAP Sync to transfer the emails.

Let’s install packages on both CentOS and Ubuntu one by one. Then we will understand how to use the command. Because installation is different for both OS, but functionality is the same on both.

Read Also: How to Install and Use PHP Composer on CentOS 7 and 8

Install Imapsync on CentOS 7 / 8

  • We need to install EPEL package repository. Imapsync package is available under the EPEL package repository.
sudo yum install epel-release
  • Install Imapsync package
sudo yum install imapsync

Let’s Install Imapsync on Ubuntu 16.04 / 20.04

  • To Install Dependencies with the following command
sudo apt-get install libauthen-ntlm-perl libclass-load-perl libcrypt-ssleay-perl libdata-uniqid-perl libdigest-hmac-perl libdist-checkconflicts-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-dbus-perl libnet-ssleay-perl libpar-packer-perl libreadonly-perl libregexp-common-perl libsys-meminfo-perl libterm-readkey-perl libtest-fatal-perl libtest-mock-guard-perl libtest-mockobject-perl libtest-pod-perl libtest-requires-perl libtest-simple-perl libunicode-string-perl liburi-perl libtest-nowarnings-perl libtest-deep-perl libtest-warn-perl make cpanminus
  • Download Imapsync package from git.
git clone https://github.com/imapsync/imapsync.git
  • We need to compile imapsync first, so we need to run below command.
cd imapsync
mkdir dist
sudo make install
  • Check the Imapsync Version
imapsync -v

Transfer Emails with IMAP

To transfer the mail, follow the below command

imapsync --host1 Source_Ip --user1  Source_Email  --password1 Source_Email_Password --host2 Destination_Ip --user2 Destination_Email   --password2 Destination_Email_Password

–host1 – Put the Source server IP address or imap.source.example.com.

–user1 – Input the Source Email Address.

–password1 – Enter the Source email address’s password.

–host2 – Mention the Destination’s server IP address or imap.source.example.com.

–user2 – Put the Destination Email Address.

–password2 – Mention the Destination email address password.

For Example:-

imapsync --host1 192.148.155.005 --user1 [email protected]  --password1 sdgfvd@EE#S5m --host2 192.122.585.125 --user2 [email protected]   --password2 sds@syg7!dess*n

In the above command –host1 (192.148.155.005) represents the source server and –host2 (192.122.585.125) represents the destination server. The –user1 ([email protected]) represents the source mail account and –user2 ([email protected]) represents the destination mail account. The –password1 (sdgfvd@EE#S5m) represents the password of the source mail account and –password2 (sds@syg7!dess*n) represents the password of the destination mail account.

Transfer Emails with IMAP SSL

To transfer the mail over SSL, follow the below command

imapsync --host1 Source_Ip --user1 Source_Email  --password1 Source_Email_Password --ssl1 --port1 993 --host2 Destination_Ip --user2 Destination_Email --password2 Destination_Email_Password --ssl2 --port2 993

–host1 – Put the Source server IP address or imap.source.example.com.

–user1 – Input the Source Email Address.

–password1 – Enter the Source email address’s password.

–ssl1 –port1 993 – Define the SSL port.

–host2 – Mention the Destination’s server IP address or imap.source.example.com.

–user2 – Put the Destination Email Address.

–password2 – Mention the Destination email address password.

–ssl2 –port2 – Define the SSL port.

For Example:-

imapsync --host1 192.148.155.005 --user1 [email protected]  --password1 sdgfvd@EE#S5m --ssl1 --port1 993 --host2 192.122.585.125 --user2 [email protected]   --password2 sds@syg7!dess*n --ssl2 --port2 993

Conclusion

In this, we have learned how to install and Migrate Mails with the IMAP Sync server to another IMAP server. We need this tool when someone wants to migrate the entire mailbox to a new server from his old server.

If you guys have any queries about this tutorial, let me know in the comments.