SSH Commands to Migrate Webmail to Webmail on another server Print

  • vps mail transfer, imapsync, cpanel to cwp, move webmail, email migration, transfer emails
  • 0

If you are moving your website to our hosting services and want to bring your existing emails with you, using the IMAP Sync method is the most reliable way. Unlike manual file transfers, this method logs into both mailboxes and synchronizes every folder (Inbox, Sent, Drafts, etc.) while preserving original timestamps.

Prerequisites

  • Root access to your new VPS or Dedicated Server.
  • The IP address of your old server.
  • The email address and password for both the old and new mailboxes.
  • Port 993 (IMAP SSL) must be open on both servers' firewalls.

Step 1: Install imapsync

Log into your new server via SSH (using a tool like Termius) and install the migration utility:

# For AlmaLinux, CentOS, or CloudLinux
yum install imapsync -y

# For Ubuntu or Debian
apt install imapsync -y

Step 2: Run the Migration Command

Run the following command, replacing the placeholders with your actual server IPs, email addresses, and passwords.
Pro Tip: Run this inside a screen or tmux session to ensure the migration continues even if you close your terminal.

imapsync --host1 [OLD_SERVER_IP] \
--user1 [EMAIL_ADDRESS] \
--password1 "OLD_PASSWORD" \
--ssl1 \
--host2 [NEW_SERVER_IP] \
--user2 [EMAIL_ADDRESS] \
--password2 "NEW_PASSWORD" \
--ssl2 \
--automap --addheader --syncinternaldates \
--log --logfile /root/migration.log

What do these options do?

  • --ssl1 / --ssl2: Ensures the connection is encrypted and secure.
  • --automap: Automatically matches folders like "Sent" and "Trash" even if the folder names are slightly different.
  • --addheader: Adds a header to migrated emails to track the process.
  • --syncinternaldates: Crucial. This keeps the "Date Received" the same as the original so your emails aren't all dated "Today."

Step 3: Verification

Once the process finishes, check the summary at the bottom of your terminal. You can also view the detailed log file here: cat /root/migration.log

Log into your new Webmail (Roundcube) to confirm all folders and emails are visible. If you don't see your folders, go to Settings > Folders and ensure they are marked as Subscribed.


Important Notes

  1. DNS Changes: We recommend performing the migration before you change your MX records/DNS. Once the migration is finished, you can switch your DNS to our server.
  2. Final Sync: After changing DNS, run the command one more time to catch any emails that arrived at the old server during the propagation period.

Need Help?

If you are uncomfortable running these commands, please open a support ticket and our technical team can assist with the migration for you.


Was this answer helpful?

« Back