Email Migration Tool Open Source: Step-by-Step Guide
In this article
An open-source email migration tool lets you move mail, contacts and calendars between IMAP servers without paying for a commercial product. The most practical choice is imapsync, a long-standing Perl script that copies mailboxes over IMAP. You will need a computer with Perl (Linux, macOS, or Windows via WSL), network access to both mail servers, and the IMAP hostnames plus login credentials for the source and destination accounts. If your provider uses two-factor authentication, create an app-specific password first. This guide walks through a safe imapsync migration, from preparation to verification.
What You'll Need
- A computer running Linux, macOS, or Windows with WSL (Windows Subsystem for Linux).
- Perl 5.8 or later, plus the standard imapsync dependencies (Mail::IMAPClient, IO::Socket::SSL, and related modules).
- IMAP access enabled on both the source and destination accounts, with the server hostnames and ports (usually 993 for SSL).
- App-specific passwords if either account uses two-factor authentication.
- Enough free disk space on the destination server for the migrated mail.
- Optional: a test account on the destination to rehearse the migration before touching the real mailbox.
Step-by-Step
- Install imapsync. On Debian or Ubuntu, run
sudo apt update && sudo apt install imapsync. On macOS, install via Homebrew withbrew install imapsync. On Windows, open WSL and follow the Debian instructions. If your distribution does not package it, download the official release from the imapsync GitHub repository and run it with Perl. Avoid unofficial binaries. - Confirm IMAP is enabled on both accounts. In the source and destination webmail settings, look for an IMAP or email client access option and turn it on. Labels can differ slightly by provider and version, so check the provider's help pages if you cannot find it.
- Create app passwords if needed. If either account has two-factor authentication, generate an app-specific password in the account's security settings. Use that password in the commands below instead of your normal login password.
- Run a dry run first. imapsync has a
--dryoption that connects and reports what it would do without copying anything. Start with a single folder to check credentials and folder mapping:imapsync --host1 source.example.com --user1 you@example.com --password1 'sourcepass' --host2 dest.example.com --user2 you@example.com --password2 'destpass' --folder INBOX --dry. Replace hostnames, usernames and passwords with your own. If the dry run succeeds, remove--dryto copy the folder. - Migrate all folders. Remove the
--folderrestriction to copy every folder:imapsync --host1 source.example.com --user1 you@example.com --password1 'sourcepass' --host2 dest.example.com --user2 you@example.com --password2 'destpass'. imapsync creates missing folders on the destination and skips messages already present, so you can run it again later to pick up new mail. - Use SSL and avoid plaintext. Add
--ssl1 --ssl2if your servers support SSL on port 993 (most do). If a server requires a different port, add--port1or--port2with the correct number. Never send passwords over an unencrypted connection. - Check the log for errors. imapsync prints a summary at the end. Look for failed folders, authentication errors, or messages skipped due to size limits. Save the log to a file with
--logfile migration.logso you can review it later. - Verify the destination. Log in to the destination webmail and compare folder counts and a few recent messages. Check that sent mail, drafts and archive folders are present. If something is missing, rerun imapsync; it will copy only what is absent.
- Keep the source account active until you are satisfied. Do not delete the source mailbox until you have confirmed the destination is complete. Run imapsync once more after a few days to catch new messages, then disable the old account.
Common Mistakes
- Skipping the dry run. A dry run catches wrong hostnames, bad passwords and folder mapping issues before any data moves.
- Using your normal password with two-factor authentication. imapsync will fail to log in. Generate an app-specific password instead.
- Forgetting to enable IMAP. Many providers disable IMAP by default. If the connection is refused, check the account's email settings first.
- Assuming folder names match. Some servers use different names for Sent, Drafts or Trash. imapsync maps common folders automatically, but check the log for unmapped folders and add
--f1f2mappings if needed. - Deleting the source too early. Always verify the destination before removing the old account.
Tips
- Run the migration during off-peak hours to reduce load on both servers.
- Use
--maxageor--minageto limit the date range if you only need recent mail. - Add
--useheader Message-Idto help imapsync detect duplicates more reliably. - If the destination has a storage quota, check free space before copying large mailboxes.
- Keep the log file; it is the fastest way to diagnose a failed folder.
Troubleshooting
If imapsync cannot connect, first check the hostname and port. Try --ssl1 --ssl2 if the server requires SSL. If authentication fails, confirm the username is the full email address and that you are using an app password where required. If a folder is skipped, look for a size limit or a folder name mismatch in the log. If the process stops partway, rerun the same command; imapsync resumes by skipping messages already copied. If the destination rejects messages as too large, check the provider's attachment limit and migrate that folder separately. For persistent errors, run with --debug to get more detail, and consult the imapsync documentation for the exact option names.
Frequently Asked Questions
Is imapsync free?
imapsync is open source and free to use. Some distributions package it; you can also download it from its official repository.
Can I migrate from Gmail or Outlook.com?
Yes, if IMAP is enabled and you use an app-specific password when two-factor authentication is on. Check the provider's help pages for the correct IMAP hostname.
Will imapsync copy contacts and calendars?
No. imapsync copies email messages and folders over IMAP. Contacts and calendars use different protocols (CardDAV and CalDAV), so you need a separate tool for those.
Can I run it again after the first migration?
Yes. imapsync skips messages already present, so a second run picks up new mail without duplicating existing messages.
Does it work on Windows?
It runs on Windows through WSL. Native Windows support is not officially provided, so use WSL or a Linux machine.
What if my provider blocks IMAP?
Some providers restrict IMAP to certain plans or require you to enable it in settings. If it is not offered, imapsync cannot connect; use the provider's own export or migration tool instead.