The two most frequently used storage methods for email server side are mbox and maildir.
The mbox format is older and much less common, since its basically putting all your eggs in one basket. A single database file stores all of the mail for a single mailbox, organized by domains. These files have all of the text of the emails, along with headers and other information, concatenated together.
Maildir does what it sounds like: it stores mail in directories. Even better, the mail is stored in plaintext, so you can easily check the content from the command line. Maildir is generally one directory per mail account, organized again by domain, and subfolders for the folders set up by the user to store mail. Each folder then has a ‘cur’, ‘new’, and ‘tmp’ folder to organize incoming mail, and files are named based on delivery time and read or unread message state.
In both cases, if both servers are using the same format, you can easily
rsync the files between servers. Just make sure you set up the mailboxes on the target machine before you bring the files over, and ensure that the permissions and ownerships of the mail files match everything else on the target system.
cPanel File Migration
For each individual cPanel account, all mail is stored in the following directory:
And the metadata for the account (passwords and quotas) is stored in:
If you are migrating a full domain to another cPanel account or server, copying these two folders and fixing their ownerships is sufficient to enact the migration. But, there are a few other files to look at:
These are email forwarders, autoresponders, spamassassin settings, squirrelmail settings, horde settings, etc.
If you don’t have file-level access, or the mail storage types are different, then you will need to manually sync IMAP (internet message access protocol) data.
In order to move mail with IMAP, you need to know the username and password of each and every mailbox you would like to copy.
NOTE: the IMAP protocol will only transfer emails, not forwarders, address books, contacts, calendars, etc.
Imapsync is a perl program written by Giles Larimal, which will connect over IMAP to two mailboxes, and recursively copy mail and folder structure from one to the other.
On CentOS you can install it via yum:
yum install epel-release
yum install imapsync
After the installation run the program with the following command to test it and check if other prerequisites are needed to install Imapsync.
NOTE: Ports 143 and 993 will need to be accessible inbound and outbound to the server you are running imapsync on. You don’t have to run Imapsync on the server you are migrating to or from!
Here is how the imapsync essential command line structure looks:
imapsync --host1 mail.hostname.com --host2 mail.hostname2.com --user1 email@example.com --user2 firstname.lastname@example.org --password1 secr3tskw1rr3l --password2 secr3tskw1rr3l
--ssl1/2 for secure connections, and
--dry to ensure that the credentials are correct.
imapsync --host1 mail.hostname.com --host2 mail.hostname2.com --user1 email@example.com --user2 firstname.lastname@example.org --password1 secr3tskw1rr3l --password2 secr3tskw1rr3l --ssl1 --ssl2 --justlogin
Here is an online version of imapsync if you don’t mind typing in your passwords online.
DNS MX records
After a successful migration, we need to update the nameservers or MX, SPF and CNAME records if we are migrating emails only and not the actual website. An update in DNS MX records cannot reliably guarantee that all mail will INSTANTLY start being delivered on the target.