imapsync copies mailboxes from one IMAP server to another, keeping folders, read/unread flags and dates. It works between any providers – cPanel, Plesk, Google Workspace, Microsoft 365 or a self-hosted server – and can be re-run safely to copy only new messages. This guide shows a clean email migration with imapsync.
Before you start
- Login details for every mailbox on the old server and the new server (create the new accounts first).
- A Linux machine to run imapsync on, such as a VPS. It needs network access to both servers on port 993.
- Moving between cPanel servers? A full account transfer with the WHM Transfer Tool moves email automatically; imapsync is for other cases.
Install imapsync
- Debian/Ubuntu: install the Perl dependencies listed on the imapsync website, then download the
imapsyncscript from the official GitHub repository and make it executable. - AlmaLinux/Rocky:
sudo dnf install -y epel-release && sudo dnf install -y imapsync.
Check it works: imapsync --version.
Run a dry run
imapsync --host1 mail.oldhost.com --user1 info@example.com --password1 'OldPass' --ssl1 \
--host2 mail.newhost.com --user2 info@example.com --password2 'NewPass' --ssl2 \
--dry --justfoldersThis logs in to both, lists folders and shows what would be created, without copying anything.
Migrate one mailbox
Remove --dry --justfolders to copy everything:
imapsync --host1 mail.oldhost.com --user1 info@example.com --passfile1 /root/p1 --ssl1 \
--host2 mail.newhost.com --user2 info@example.com --passfile2 /root/p2 --ssl2 \
--automap--passfile1/2keeps passwords out of your shell history (files containing only the password, permission 600).--automapmatches special folders like Sent, Trash and Junk even when names differ.- A log is saved in the
LOG_imapsyncfolder.
Migrate many mailboxes
- Create
accounts.txtwith one line per mailbox:user1;pass1;user2;pass2. - Loop over it:
while IFS=';' read -r u1 p1 u2 p2; do imapsync --host1 mail.oldhost.com --user1 "$u1" --password1 "$p1" --ssl1 \ --host2 mail.newhost.com --user2 "$u2" --password2 "$p2" --ssl2 --automap done < accounts.txt - Delete
accounts.txtwhen finished – it contains passwords.
Cut over with no lost mail
- A day before, lower the MX record TTL to 300 seconds.
- Run the first full sync (may take hours for large mailboxes).
- Change the MX (and related SPF/DKIM) records to the new server.
- Wait for the old TTL to expire, then run imapsync again – it copies only messages that arrived meanwhile.
- Update mail apps to the new server settings.
Troubleshooting
- Authentication failed: wrong password, or the provider needs an app password or OAuth (common for Google and Microsoft).
- Messages too large: some servers limit message size; check the log and use
--maxsizeto skip huge ones if needed. - Duplicates after re-runs: imapsync normally detects existing messages by Message-ID; avoid changing folder mapping between runs.
- Slow transfer: run imapsync on a server close to both hosts; migrate mailboxes in parallel in moderation.
FAQ: imapsync email migration
Does imapsync delete mail from the old server?
No, not unless you add options like --delete1. The old mailbox stays intact.
Can it migrate contacts and calendars?
No. imapsync copies IMAP mail only; export contacts and calendars separately (CardDAV/CalDAV or files).
Can I migrate from POP3?
No. Mail downloaded via POP3 lives on your computer; upload it to the new IMAP account from your mail app.
