How to Migrate Webmail Emails to New cPanel Server
Moving email folders to a new server during a server migration ought to be easy. Email migration should be as easy as pressing a button in cPanel’s Backup Wizard. But, oh no, cPanel offers no such automated email export option.
In cPanel we can make a full backup of a server account. This back up stores emails and email account information in the directory homedir/mail/.
But, what do we do when we want to move emails from one server to another without taking a full backup of the server space? How do we migrate webmail emails between a server when the origin server has multiple addon domains or when we want only the emails and no other data?
Here is a quick and easy way to export all emails from one server and import them into another.
Assumptions
- The domain name of the email accounts has not changed.
- The new web server is devoid of emails for the email accounts being moved to it. The email restoration process deletes existing email profile data.
- Both servers use cPanel. This email migration process can be adapted to non cPanel server management software. This guide provides instructions for backing up and restoring emails for cPanel accounts only.
Server webmail migration guide
Step 1: Backup and download email folders
In this step we create an export file that contains the emails stored on OLD Server. This will be our email backup file.
- Login to cPanel on OLD Server
- Open File Manager
- Go up one directory above public_html (see image 1)
- Enter the mail directory (see image 2)
- Right-click the directory with the same name as the domain the emails belong to (see image 2)
- Compress the directory
- Download the compressed file. You might need to reload the directory to see it
The ‘mail’ directory contains subdirectories for each email domain. Each subdirectory is named after the domain the emails belong to. Every subdirectory with a domain name contains mail folders for that domain. For example, the emails for all of ANeukAceh’s email addresses are stored in /mail/aneukaceh.com e.g. /mail/aneukaceh.com/kus and /mail/aneukaceh.com/info.
Step 2: Restore email backups
In this step we import the email backup file into NEW Server.
- Login to cPanel on NEW Server
- Use cPanel to recreate the email accounts (see image 3)
- After finish recreate the email accounts*), Open File Manager
- Go up one directory above public_html (see image 1)
- Enter the mail directory (see image 2)
- Upload the email backup file
- Extract the file
- Delete the zip file
- Open webmail
- Configure Webmail to show the new email folders
*)We MUST recreate the email addresses on NEW Server First, before extract the backup file, because otherwise cPanel deletes the migrated emails when new accounts are created.
Email migration can be easy
Email migration between servers is straight forward. Create an email directory export file. Recreate email accounts on the target server before uploading the export file. Upload the export file to the target server.
The webmail migration method explained above here works when the domain name of the source server is the same as the domain name of the target server. I’ve yet to migrate email accounts between two servers with different domain names but I figure in such a case I could use sed or awk to rewrite the source server domain name written in the export file.