How to Migrate Emails Between cPanel Accounts Using imapsync (Docker Method)
Email migration is a critical task when moving hosting providers or consolidating accounts. One of the most reliable and secure tools for this process is imapsync, which allows you to synchronize emails between two IMAP servers without data loss.
In this guide, we’ll walk through a practical, production-ready method using Docker, making the process clean, repeatable, and server-safe.
This guide is prepared for implementation use cases handled by African Script, especially for clients migrating cPanel-based email systems.
What is imapsync?
imapsync is an open-source command-line tool used to synchronize emails between two IMAP servers. It is widely used for:
- cPanel to cPanel migrations
- Gmail to cPanel migrations
- Backup and replication of mailboxes
- Hosting transfers without downtime
It ensures emails, folders, flags, and metadata are preserved.
Why Use Docker for imapsync?
Using Docker simplifies installation because:
- No dependency conflicts
- Works on any Linux server
- No need to compile imapsync manually
- Easy repeatable execution
Step 1: Install Docker
On your Linux server (Ubuntu/Debian):
sudo apt update
sudo apt install -y docker.io
sudo systemctl enable docker
sudo systemctl start docker
Verify installation:
docker --version
Step 2: Pull imapsync Docker Image
We will use a ready-made image:
docker pull gilleslamiral/imapsyncThis image contains everything needed to run imapsync immediately.
Step 3: Prepare Your cPanel Email Details
You need the following for both source and destination:
Source (Old cPanel)
- IMAP server (e.g. mail.old-domain.com)
- Email address
- Password
- Port (usually 993 for SSL)
Destination (New cPanel)
- IMAP server (e.g. mail.new-domain.com)
- Email address
- Password
- Port (993 SSL)
Step 4: Run imapsync via Docker
Execute the migration command:
docker run --rm gilleslamiral/imapsync \--host1 mail.old-domain.com \
--user1 user@olddomain.com \
--password1 'OLD_PASSWORD' \
--ssl1 \
--host2 mail.new-domain.com \
--user2 user@newdomain.com \
--password2 'NEW_PASSWORD' \
--ssl2
Step 5: Understanding the Command
-
host1→ Source mail server -
user1→ Source email -
password1→ Source password -
host2→ Destination mail server -
user2→ Destination email -
ssl1 / ssl2→ Enables secure SSL connection --rm→ Removes container after completion
Step 6: Optional Advanced Flags (Recommended)
For production migrations, use:
Skip already migrated emails
--automap
Keep all flags and read states
--syncinternaldates
Dry run (test before actual migration)
--dry
Example:
docker run --rm gilleslamiral/imapsync \--host1 mail.old-domain.com \
--user1 user@olddomain.com \
--password1 'OLD_PASSWORD' \
--ssl1 \
--host2 mail.new-domain.com \
--user2 user@newdomain.com \
--password2 'NEW_PASSWORD' \
--ssl2 \
--automap \
--syncinternaldates
Step 7: Verify Migration
After completion:
- Log into new cPanel webmail
- Check folder structure
- Confirm email counts match
- Spot-check recent and old emails
Common Issues & Fixes
1. Authentication Failed
- Confirm password correctness
- Check IMAP is enabled in cPanel
2. Connection Timeout
- Verify port 993 is open
- Check firewall rules
3. Missing Emails
- Re-run imapsync (it is safe; it skips duplicates)
Why This Approach is Ideal for Agencies
For agencies like African Script, this method is ideal because:
- Fully automated migration workflow
- No reliance on cPanel backups
- Works across different hosting providers
- Scales for multiple clients
- Minimizes downtime risk
Using imapsync with Docker is one of the most efficient and professional ways to migrate email accounts between cPanel servers. It ensures reliability, security, and full data integrity without manual export/import risks.
For agencies handling multiple migrations, this method becomes a repeatable operational standard.
