Skip to content

Migrate mailboxes into cPanel from any IMAP host with imapsync

How to move existing mailboxes into a cPanel server from another host, Microsoft 365, or Gmail using imapsync, then cut the MX over with no lost mail.

Moving a client’s existing mailboxes onto a cPanel server means copying years of mail — every folder, read state, and flag — from wherever it lives now to the new mailboxes, then switching the MX so new mail arrives at cPanel instead of the old host. The tool for the copy is imapsync, which synchronizes one IMAP account to another and can run repeatedly so the final pass picks up only what changed. Done in the right order — create mailboxes, pre-sync, cut over, final sync — users move with their full history and no gap. This runbook covers that sequence for any IMAP source: another cPanel host, a generic provider, Microsoft 365, or Gmail.

What’s happening

A mailbox migration is really two independent problems. The first is the data copy: getting the messages from the source server into the destination Maildir. imapsync solves this by logging into both accounts over IMAP and copying messages the destination does not already have, preserving folder structure, seen/answered flags, and dates. Because it only copies the delta on each run, you can sync the bulk of the mail before cutover while the old server is still live, then run a quick final sync after cutover to catch the last messages.

The second problem is the cutover: changing the MX record so senders deliver to cPanel instead of the old host. The two must be sequenced carefully. If you change the MX before the mailboxes and authentication are ready, mail bounces; if you do the final imapsync before the MX change has fully propagated, messages that arrive at the old server in the propagation window get missed. The clean pattern is to lower the MX TTL ahead of time, pre-sync, change the MX, let it propagate, then run a final imapsync against the old server to sweep up anything delivered there during the switch. Microsoft 365 and Gmail add wrinkles — app passwords or OAuth, and throttling — but the shape is the same.

How to verify

Confirm imapsync is available and that you can reach both servers.

# imapsync present? (install from EPEL or the source if not)
imapsync --version 2>/dev/null || which imapsync

# Can you reach the source and destination IMAP over TLS?
openssl s_client -connect oldhost.example:993 </dev/null 2>/dev/null | head -3
openssl s_client -connect mail.example.com:993 </dev/null 2>/dev/null | head -3

Before cutover, check the current MX and lower its TTL:

# Where does mail go now, and what is the TTL?
dig MX example.com +noall +answer
# Lower the TTL in DNS days ahead so cutover propagates fast.

After creating the destination mailbox, confirm it exists and is empty, then dry-run the sync:

# Destination Maildir created by cPanel?
ls -la /home/<cpaneluser>/mail/example.com/user/

# Dry run: see what WOULD copy, change nothing
imapsync --dry \
  --host1 oldhost.example --user1 user@example.com --password1 'OLDPASS' --ssl1 \
  --host2 mail.example.com --user2 user@example.com --password2 'NEWPASS' --ssl2

The fix

  1. Create the destination mailboxes first — in cPanel » Email Accounts, create each address with its quota before any sync. imapsync copies into an existing mailbox; it does not create accounts. Match addresses one-to-one with the source.

  2. Lower the MX TTL several days ahead — in WHM » DNS Zone Manager, drop the MX record TTL (e.g. to 300 seconds) well before cutover day. This is the cheapest way to make the eventual switch propagate in minutes instead of hours, shrinking the window where mail could split between servers.

  3. Pre-sync each mailbox while the old server is live — run imapsync without --dry to copy the bulk of the mail ahead of cutover. Users keep working on the old server; you are just staging their history on cPanel. Repeat for every account, scripting it from a list for many users.

    imapsync \
      --host1 oldhost.example --user1 user@example.com --password1 'OLDPASS' --ssl1 \
      --host2 mail.example.com --user2 user@example.com --password2 'NEWPASS' --ssl2
  4. Use app passwords or OAuth for Microsoft 365 and Gmail sources — those providers block plain-password IMAP. Generate an app password (with their security settings) or use imapsync’s OAuth options for --host1, and expect to add --gmail1 / provider-specific flags and slower throttling so the source does not rate-limit you.

  5. Cut the MX over to cPanel — once pre-sync is done and the destination domain authenticates (SPF/DKIM set in Email Deliverability, domain set to Local Mail Exchanger), change the MX to point at the cPanel server. New mail now flows to cPanel. Confirm with dig MX example.com @8.8.8.8.

  6. Run a final imapsync after propagation — after the MX change has propagated, run imapsync once more against the old server for each account to sweep up any messages delivered there during the switch. This final delta pass is what guarantees no message is left behind.

  7. Verify and decommission — have users connect to the cPanel mailbox (IMAP settings from Connect Devices), confirm folders, counts, and flags match, and that new mail arrives. Only after users confirm should you close the old mailboxes, so the old copy remains a fallback until everyone is settled.

When the final sync shows zero new messages to copy and users see their full history plus new arrivals on cPanel, the migration is complete and the old host can be retired. The discipline that prevents lost mail is the ordering — pre-sync, cut over, final sync — not the imapsync command itself. Stack Harbor runs cPanel mailbox migrations under cPanel server administration — start a conversation.