We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – Import Mail accounts from one server to another using Imapsync

Learn how to – Import Mail accounts from one server to another using Imapsync.

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

How To Install imapsync on Linux

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

Install imapsync on CentOS 8 / Rocky Linux 8 / AlmaLinux 8

Install required tools:

sudo yum -y install wget perl-App-cpanminus gcc

Install the following Perl module:

sudo cpanm lazy Test::MockObject

Download and installimapsync:

wget https://imapsync.lamiral.info/imapsync
perl -Mlazy imapsync
chmod +x imapsync

Test it’s working:

./imapsync --testslive
./imapsync --tests

Install imapsync on CentOS 7

Enable EPEL repository on CentOS 7 system:

sudo yum install epel-release

Install imapsync on CentOS 7 from EPEL repo

sudo yum install imapsync

Confirm successful installation:

# Test
$ imapsync

# A live test:
$ imapsync --testslive --tls1 --ssl2

# Unit tests
$ imapsync --tests

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  
cpanminus

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

sudo cpanm Data::Uniqid Mail::IMAPClient JSON::WebToken

3. Now download imapsync tarball and install it.

Check for the latest here: https://github.com/imapsync/imapsync/releases

wget https://github.com/imapsync/imapsync/archive/refs/tags/imapsync-2.140.tar.gz
tar zxvf tar zxvf imapsync*
cd imapsync-imapsync*

Do a dependencies test that shows also the basic example:

$ ./imapsync

A live test showing imapsync job:

$ ./imapsync --testslive

Now the install command (need root priviledges again):

sudo cp imapsync /usr/bin/

Now go to read http://imapsync.lamiral.info/#doc start with the tutorial.

Installation reference:

Import Mail accounts from one server to another using Imapsync

Below is a basic usage example of Imapsync:

imapsync --host1 server1.example.com 
 --user1 user@domain.com --password1 secret1 
 --host2 server2.example.com 
 --user2 user@domain.com --password2 secret2

Note that server1.example.com and server2.example.com must be replaced with appropriate IP addresses or hostnames of the mail servers.

Using Imapsync: Migrating Email accounts

To use imapsync with multiple accounts, we’ll need to create a file with usernames and passwords like below:

$ vim $HOME/accounts.txt

Add Mailbox accounts with passwords.

host1_1;user1_1;password1_1;host1_2;user1_2;password1_2;
host2_;user2_1;password2_1;host2_2;user2_2;password2_2;
host3_1;user3_1;password3_1;host3_2;user3_2;password3_2;
#next line
  • 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/imapsync-batch.sh<<EOF
#!/bin/bash
echo "Looping on account credentials found in accounts.txt"
echo ""
{ while IFS=';' read  h1 u1 p1 h2 u2 p2 fake
    do 
        { 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" 
                 "$@"  
        echo "==== Ended imapsync from host1 $h1 user1 $u1 to host2 $h2 user2 $u2 ===="
        echo
    done 
} < $HOME/accounts.txt
EOF

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

$ bash $HOME/imapsync-batch.sh

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.

Cart

Your Cart is Empty

Back To Shop