You’re switching email providers — Gmail to your domain, old host to iWebVault, Outlook to something cheaper. You don’t want to lose years of mail. The right tool is IMAPSync, a battle-tested utility that copies mail between IMAP servers preserving folders, dates, read/unread state, flags, and message integrity. This guide covers when to use it, how to run it, and the gotchas around large mailboxes.
When IMAPSync is the right tool
- Both old and new providers support IMAP (almost all do).
- You want to migrate the actual messages, not just forward future mail.
- You need to preserve folder structure (Sent, Drafts, custom folders).
- You want to keep historical dates intact, not re-arrive everything as today.
- You’re moving multiple mailboxes or doing this regularly.
NOT needed when:
- You only have a small mailbox and you can use desktop client drag-and-drop instead (Thunderbird makes this trivial).
- You’re abandoning the old email entirely and don’t need to keep messages.
- The provider offers its own migration service (Google Workspace’s Data Migration Service for incoming).
What you need before starting
- Source server credentials — IMAP hostname, port, username, password.
- Destination server credentials — same for new mailbox.
- Destination mailbox already created and ready to receive mail.
- If using Gmail as source: app password (Google blocks regular passwords for IMAP).
- A server / machine to run IMAPSync from (or our team via support ticket).
Running IMAPSync
IMAPSync is a Perl script. Most installations on Linux. Basic invocation:
imapsync
--host1 imap.old-provider.com --port1 993 --ssl1
--user1 you@old-domain.com --password1 'YOUR_OLD_PASSWORD'
--host2 mail.iwebvault.com --port2 993 --ssl2
--user2 you@your-domain.com --password2 'YOUR_NEW_PASSWORD'
That’s the minimum. IMAPSync connects to both, lists folders, and starts copying messages. Output streams to your terminal showing progress.
Common options worth adding
# Just test, don't actually copy (review what would happen)
--dry
# Resume after interruption (skip already-copied messages)
# Default behavior - IMAPSync detects already-copied messages
# Limit speed if your hosting is rate-limiting
--maxbytespersecond 500000 # 500KB/s
# Exclude specific folders
--exclude 'Spam|Trash|All Mail'
# Map folder names (Gmail has "[Gmail]/Sent Mail" vs cPanel's "Sent")
--regextrans2 's/[Gmail]/Sent Mail/Sent/'
--regextrans2 's/[Gmail]/Drafts/Drafts/'
--regextrans2 's/[Gmail]/Trash/Trash/'
For Gmail specifically, regex transforms map Google’s “[Gmail]/” prefix to standard folder names. Without this you end up with weird folder names on the new server.
Gmail-specific considerations
Get an App Password
- Google Account → Security → 2-Step Verification (enable if not already).
- App passwords → create new.
- Pick “Other” device, name it “IMAPSync migration”.
- Copy the 16-character password Google generates.
- Use this as password1 in your IMAPSync command. Don’t use your regular Google password.
Skip Gmail’s special folders
Gmail’s “All Mail” is a virtual folder containing duplicates of everything else. Don’t migrate it — you’d duplicate every message:
--exclude '[Gmail]/All Mail'
--exclude '[Gmail]/Important'
--exclude '[Gmail]/Starred'
Star/Important labels in Gmail don’t have direct equivalents in standard IMAP anyway.
Timing for large mailboxes
Rough sync rates:
- 1,000 messages — 5-15 minutes.
- 10,000 messages — 30-90 minutes.
- 50,000 messages — 3-8 hours.
- 100,000+ messages — overnight job.
Highly variable based on average message size, attachment counts, and how aggressively each provider rate-limits IMAP. Gmail rate-limits aggressively to about 2,500 messages/hour outbound.
For huge mailboxes, run in batches by folder. Migrate Inbox first (most needed), then Sent, then others.
Cutover sequence — minimizing email loss during transition
The risky window is between “I’ve migrated old mail” and “DNS points to new server”. Mail arriving during this gap goes to the old server.
- Set up new mailboxes on iWebVault. Test that you can send/receive directly via the new server’s IP.
- Initial IMAPSync. Copy current mail from old to new. Can take hours.
- Lower DNS TTL. On old DNS provider, change MX TTL to 300 seconds. Wait the original TTL (often 1 hour) for this to propagate.
- Change MX records to point to iWebVault.
- Run IMAPSync again — picks up any mail that arrived at old server during DNS propagation window.
- Verify all mail arrived at new server. Compare message counts in both.
- Final IMAPSync run after 24 hours to catch any stragglers.
- Cancel old mailbox only after a week of confidence everything moved.
For business-critical migrations, accept some downtime (1-2 hours) by:
- Setting auto-responder on old account: “We’ve moved! Please resend to…”
- Doing migration during low-traffic window (Sunday morning).
Running IMAPSync without setting up a server
If you don’t have a Linux server to run IMAPSync from:
- Open a ticket with iWebVault. For new customer migrations we can run IMAPSync as part of onboarding.
- Online IMAPSync services. imapsync.lamiral.info offers paid migration runs.
- Use a VPS short-term. Spin up a $5 VPS, run IMAPSync, destroy it after migration.
Verifying migration succeeded
- Message count. IMAPSync output shows “Messages transferred” totals. Compare to source folder counts.
- Folder structure. Open the new mailbox; ensure all folders present.
- Date integrity. Open old messages; dates should match originals, not “today”.
- Attachments. Open a few messages with attachments to verify they came through.
- Search. Search for a known message; should find it.
Common issues
“Authentication failed for Gmail.” Need app password, not regular password. Also enable IMAP in Gmail Settings → POP/IMAP first.
“Gmail rate-limited after first hour.” Use --maxbytespersecond 500000 to throttle below Gmail’s limits. Run in batches across multiple sessions.
“Folder names look weird on new mailbox.” Need regextrans2 transforms for Gmail’s bracket-prefixed folders. See gmail section above.
“Some messages duplicate.” IMAPSync usually detects duplicates via Message-ID headers. If duplicates persist, source and destination have different Message-IDs (rare). Run with --useheader 'Message-Id' to enforce.
“My new mailbox quota fills up before sync completes.” Plan ahead — destination needs at least as much quota as source mailbox size.
What’s next
- Setting up mail clients with new mailboxes: Email on devices.
- Authentication for outbound deliverability after migration: SPF/DKIM/DMARC.
- Quota management on new mailboxes: Email quota guide.
IMAPSync is the gold-standard migration tool — preserves everything you care about, handles edge cases, and works across providers. The complexity is mostly in coordinating the cutover. For mailboxes you actively use, plan a careful sequence; for archived accounts, just run it once and move on.
Was this helpful?
Thanks for your feedback!