Seville, Spain
Seville, Spain
+(34) 624 816 969
Table of contents [Show]
When a company changes its email provider (for example, moving from classic hosting to Microsoft 365 or a server managed by ForgeNEX), the biggest fear is always the same: losing important emails, folders, or attachments.
There are many tools that promise to make it easy, but few are as solid as imapsync, a free utility that copies messages from one IMAP account to another without touching the originals and maintaining the entire structure.
Here is a practical guide to using it safely.
imapsync and why use it?imapsync is a command-line tool written in Perl that allows you to synchronize two IMAP mailboxes. It is ideal when:
You are migrating from an old server to a new one.
You are switching providers (e.g., from Gmail or Roundcube to Microsoft 365, Zoho, CyberPanel, etc.).
You want to maintain a mirror copy of a mailbox (incremental backup).
Its great advantage: it doesn't delete anything from the source, and you can repeat the operation as many times as you want; it only transfers new or modified messages.
On most Linux systems, you can install it like this:
If it's not in your repository (some older Debian or minimalist systems), you can install it from the source:
To check that it's operational:
Let's say you are migrating from an old server (mail.oldserver.com) to a new one (mail.newserver.com).
Key Parameters:
--ssl1 --ssl2: forces a secure connection.
--automap: detects differences in folder names (e.g., “Sent” vs “Enviados”).
--syncinternaldates: preserves the original dates of the emails.
--delete2duplicates: avoids duplicate messages if you sync multiple times.
Some services (like Gmail or Office 365) limit the number of IMAP connections or traffic per hour. If you see errors like rate limit or Too many connections, add pauses:
You can also split the migration by critical folders first (Inbox, Sent) and then the rest. Example:
Once the initial bulk copy is done, you can run the same command again every night during the transition. It will only copy new or modified messages. This way, when you change the DNS or MX records, the mailboxes will already be up to date without any interruptions.
If you manage many accounts (typical in companies with multiple users), create a file named users.txt with this structure:
And then:
After the copy is complete:
Verify the total number of folders and messages on both sides.
Open a test account and check old email headers.
Use the --dry parameter to simulate the process before a real run.
Never run bulk migrations without making previous backups.
Use an intermediary machine (a VPS or local server) to avoid overloading the source and destination servers.
If a server blocks your IP due to excessive attempts, adjust the --maxbytespersecond or the interval.
Save logs: --logfile "user.log" helps with debugging and documentation.
imapsync remains, in 2025, the most stable tool for migrating IMAP emails in a controlled and professional manner, without depending on third-party services or limited web interfaces.
It's perfect for SMEs that want to maintain control of their data and for administrators looking for secure and repeatable solutions.
And if you work with panels like CyberPanel, HestiaCP, or Microsoft 365, you can easily integrate it into automation scripts or cron jobs to keep backups synchronized.