Imapsync is a powerful tool that allows for the migration of email messages between two IMAP servers with high fidelity, preserving folder structure, message flags, and timestamps. This utility is invaluable for administrators and users undergoing email migrations due to server changes or when consolidating email accounts. This article guides you through installing and using Imapsync on Ubuntu and Debian systems.

Advertisement

Prerequisites

  • Two IMAP servers (source and destination) with active email accounts.
  • A machine running Ubuntu or Debian.
  • Command-line/terminal access.
  • Sudo privileges or root access.

Step 1: Prepare Your System

Imapsync is not available in the default Ubuntu or Debian repositories but can be installed via a third-party repository or by downloading and running the Perl script directly. We will focus on the latter method for its simplicity and because it ensures you’re getting the latest version directly from the source.

1. Update Your System

Before starting, make sure your system packages are up-to-date:

sudo apt update && sudo apt upgrade -y

2. Install Required Dependencies

Imapsync depends on several Perl modules. Install them by running:

sudo apt-get install git rcs make makepasswd cpanminus \
     gcc libssl-dev libauthen-ntlm-perl \ 
     libclass-load-perl libcrypt-ssleay-perl liburi-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-ssleay-perl libpar-packer-perl \
     libreadonly-perl libsys-meminfo-perl libterm-readkey-perl \
     libtest-fatal-perl libtest-mock-guard-perl libtest-pod-perl \
     libtest-requires-perl libtest-simple-perl libunicode-string-perl

3. Install Python Modules

Also, install required Python modules using CPAN on your system.

sudo cpanm Crypt::OpenSSL::RSA Crypt::OpenSSL::Random --force
sudo cpanm Mail::IMAPClient JSON::WebToken Test::MockObject
sudo cpanm Unicode::String Data::Uniqid

Step 2: Install Imapsync

After completing the installation of required packages. Download latest imapsync code from its official Github repository on your local system.

git clone https://github.com/imapsync/imapsync.git

Navigate to newly cloned repository and install it with the following commands on your system.

cd imapsync
mkdir -p dist
sudo make install

At this stage, your system is ready to migrate all data from one email account to another email accounts using IMAP.

Step 3: Transfer Emails with IMAP

Now that Imapsync is installed, you can start the migration process. The basic syntax for the imapsync command is as follows:

imapsync --host1 imap.source.example.com  \
	   --user1 user@example.com 	    \
	   --password1 S0urcePassw0rd  	    \
	   --ssl1			    \
	   --host2 imap.dest.example.com    \
	   --user2 user@example.com 	    \
	   --password2 Dest1nat10NPassw0rd  \
	   --ssl2

The command will take a long time as per the size of your source Mailbox. After completing all process, you will see a long list of output. Check the output to find if any error occurred during transfer. Below is the small part of the result.


Transfer started at Thu May 11 11:45:37 2017
PID is 4969
...
...
...
Total bytes transferred           : 78373 (76.536 KiB)
Total bytes duplicate host1       : 0 (0.000 KiB)
Total bytes duplicate host2       : 0 (0.000 KiB)
Total bytes skipped               : 0 (0.000 KiB)
Total bytes error                 : 0 (0.000 KiB)
Message rate                      : 0.1 messages/s
Average bandwidth rate            : 3.0 KiB/s
Memory consumption                : 217.0 MiB
Biggest message                   : 57947 bytes (56.589 KiB)
Memory/biggest message ratio      : 3927.0
Start difference host2 - host1    : -2 messages, -78373 bytes (-76.536 KiB)
Final difference host2 - host1    : 0 messages, 0 bytes (0.000 KiB)
Detected 0 errors

Conclusion

Imapsync is a robust tool for migrating emails between IMAP servers. While the installation process on Ubuntu and Debian involves a few steps, including setting up necessary Perl dependencies, the actual migration process is straightforward. Remember to review the imapsync documentation and use the –help flag to explore all available options to customize your email migration process effectively.

Migrating emails can be a sensitive operation, so always ensure you have backup copies of important emails before proceeding. Happy migrating!

Reference:

Share.

15 Comments

  1. i’ve following your instruction and need 2 more packages to be installed:
    – apt install apt-file
    and
    -apt install libtest-most-perl

    before executing sudo make install command. Please update the tutorial, thanks for the guide!

  2. Needed to also install the following:
    sudo apt-get install libwww-perl

    // run test
    pi@raspberrypi:~/imapsync $ pwd
    /home/pi/imapsync
    pi@raspberrypi:~/imapsync $ ./imapsync –testslive

  3. Bruno Martins on

    I have followed all instructions, even those in the comments but still…

    Ok: Found cpanm cpanm (App::cpanminus) version 1.7044 (/usr/bin/cpanm)
    make: *** [Makefile:99: testp] Error 1

  4. I needed these packages too, May 2021, Ubuntu 20.04
    sudo apt-get install -y libregexp-common-perl libfile-tail-perl libencode-imaputf7-perl

  5. Cédric Barthe on

    Same for me today on ubuntu 20.04, had to install the following too :

    sudo cpanm Crypt::OpenSSL::RSA Encode::IMAPUTF7 File::Tail JSON::WebToken::Crypt::RSA Regexp::Common Encode::IMAPUTF7 Test::Deep

    So the following lien is enough for installing all perl modules in one time :

    sudo cpanm Mail::IMAPClient JSON::WebToken Test::MockObject Unicode::String Data::Uniqid Crypt::OpenSSL::RSA Encode::IMAPUTF7 File::Tail JSON::WebToken::Crypt::RSA Regexp::Common Encode::IMAPUTF7 Test::Deep

    • Debian 10:
      apt-get install apt-file; apt-file update
      cpanm Encode::IMAPUTF7 File::Tail LWP::UserAgent Regexp::Common Test::Deep

      Add these before make install as well.

  6. I had the same problem. Make sure you run everything as root (via sudo). I got stuck because Crypt::OpenSSL::RSA would not install because Crypt::OpenSSL::Random was not installed. I was finally able to install that after running:

    sudo apt-get install libssl-dev

    Run ‘sudo cpanm Crypt::OpenSSL::Random’ and ‘sudo cpanm Crypt::OpenSSL::RSA’ after that.

    I was finally able to get successful build after that. You may encounter other issues. Running ‘make -d’ will give more info about where the build is failing. I also ran ‘sh -x INSTALL.d/prerequisites_imapsync’ to help track things down. Hope this helps.

    Wendy

    • Hi Wendy,
      I hope you are doing well. I have followed all steps to install imapsync. When i enter imapsync then imapsync: command not found error is showing. Kindly help me to sort out this issue. Thanks

    • Per Mejdal Rasmussen on

      Th e autor should really test the guide with a clean install. the packages “ssl” and “libssl-dev” are missing

      To recover:
      sudo apt-get install gcc
      sudo apt-get install libssl-dev
      sudo cpanm Crypt::OpenSSL::Random –force
      sudo cpanm Crypt::OpenSSL::RSA –force
      sudo make clean
      sudo make install

  7. Portátiles de ocasión on

    Hy, thx for this tuto.
    I try in Linux Mint 19.2.

    The installation is missing various packages of cpan:

    Failure: Not found Perl module File::Tail
    Failure: Not found Perl module Package::Stash::XS
    Failure: Not found Perl module Regexp::Common
    Failure: Not found Perl module Test::Deep

    to install it:
    sudo cpanm File::Tail Package::Stash::XS Regexp::Common Test::Deep

    and ready, to me it already works correct.
    Thx.

  8. Hello,

    I hope you can still answer my question. Done everything you suggested but an error came up with installing IMAP. Here is the error I get:

    ~/imapsync$ sudo make install
    cat: ./VERSION_EXE: Aucun fichier ou dossier de ce type
    sh INSTALL.d/prerequisites_imapsync
    $SHELL says /bin/bash
    $0 gives INSTALL.d/prerequisites_imapsync
    ps -ef gives root 7503 7484 0 14:05 pts/1 00:00:00 sh INSTALL.d/prerequisites_imapsync
    Distributor ID: Debian
    Description: Debian GNU/Linux 9.9 (stretch)
    Release: 9.9
    Codename: stretch
    Linux Ark 4.9.0-9-amd64 #1 SMP Debian 4.9.168-1+deb9u3 (2019-06-16) x86_64 GNU/Linux
    Ok: Found Perl 5.24.1
    Ok: Found make GNU Make 4.1
    Ok: Found Perl module App::cpanminus
    Ok: Found Perl module Authen::NTLM
    Ok: Found Perl module CGI
    Ok: Found Perl module Compress::Zlib
    Failure: Not found Perl module Crypt::OpenSSL::RSA
    Ok: Found Perl module Data::Dumper
    Ok: Found Perl module Data::Uniqid
    Ok: Found Perl module Digest::HMAC
    Ok: Found Perl module Digest::HMAC_MD5
    Ok: Found Perl module Digest::MD5
    Ok: Found Perl module Dist::CheckConflicts
    Ok: Found Perl module Encode::Byte
    Ok: Found Perl module File::Copy::Recursive
    Ok: Found Perl module IO::Socket::INET
    Ok: Found Perl module IO::Socket::INET6
    Ok: Found Perl module IO::Socket::SSL
    Ok: Found Perl module IO::Tee
    Ok: Found Perl module JSON
    Ok: Found Perl module JSON::WebToken
    Failure: Not found Perl module JSON::WebToken::Crypt::RSA
    Ok: Found Perl module HTML::Entities
    Ok: Found Perl module LWP::UserAgent
    Ok: Found Perl module Mail::IMAPClient
    Ok: Found Perl module Module::Implementation
    Ok: Found Perl module Module::Runtime
    Ok: Found Perl module Module::ScanDeps
    Ok: Found Perl module Net::SSLeay
    Ok: Found Perl module Package::Stash
    Ok: Found Perl module Package::Stash::XS
    Ok: Found Perl module PAR::Packer
    Ok: Found Perl module Parse::RecDescent
    Ok: Found Perl module Pod::Usage
    Ok: Found Perl module Readonly
    Failure: Not found Perl module Regexp::Common
    Ok: Found Perl module Sys::MemInfo
    Ok: Found Perl module Term::ReadKey
    Ok: Found Perl module Test::Fatal
    Ok: Found Perl module Test::Mock::Guard
    Ok: Found Perl module Test::MockObject
    Ok: Found Perl module Test::More
    Ok: Found Perl module Test::Pod
    Ok: Found Perl module Test::Requires
    Ok: Found Perl module Test::NoWarnings
    Ok: Found Perl module Test::Deep
    Ok: Found Perl module Test::Warn
    Ok: Found Perl module Try::Tiny
    Ok: Found Perl module Unicode::String
    Ok: Found Perl module URI::Escape

    What you have to do before using imapsync:
    Install Perl module Crypt::OpenSSL::RSA
    Install Perl module JSON::WebToken::Crypt::RSA
    Install Perl module Regexp::Common
    Here is a cpanm command to install missing Perl modules:
    cpanm Crypt::OpenSSL::RSA JSON::WebToken::Crypt::RSA Regexp::Common
    Makefile:99 : la recette pour la cible « testp » a échouée
    make: *** [testp] Erreur 1

    Some modules/librairies seem to be missing. Any advice.

    Thanks.

    Simon

    • Execute this command

      sudo cpanm File::Tail CGI Crypt::OpenSSL::RSA JSON::WebToken::Crypt::RSA Regexp::Common Test::Deep

Leave A Reply

Exit mobile version