Migrating mail from one host to the other

I was in the process of migrating a host from Helm 4 to DirectAdmin, and it seems that Helm is pretty crappy and does not store mail in user’s storage, but instead in its own mail manager, but what else would someone expect of something Windows based.

The problem and solution I describe here is applicable to all hosting managers, not just DA and Helm, but I use those in my examples.

First step is to transfer files, which is pretty easy. You could zip the whole folder in any control panel (sometimes its referred to as Backup), then get it via wget’s ftp functionality:

wget -r ftp://user:[email protected]/folder/file.zip

I’m assuming you have SSH access on your destination, or otherwise you have to do everything on your own computer and then move to the destination, which is not very engineery! Then you unzip and relocate the files.

Then you have to move databases, which is pretty easy using mysqldump tool and mysql <dumpfile.sql trivia. Transferring the dumpfile is also done with wget or ftp. Keep in mind to export/import via terminal and not something like phpMyAdmin, as encoding problems could make your life miserable.

Third and the most tedious and important step for every major website, is delivering mail. Unfortunately many hosting providers do not let you grab all your mail in a single shot, and many others do not let you import them that easily. Mail is a little complicated these days with all the MTA and MDA and Maildir and Mbox formats and all.

The proposed solution of many hosting providers is to use Outlook on imap, download all mail from source, reconnect to destination and upload all mail to destination. This involves your personal system and is way slow for huge number of mails and mailboxes.

The better way would be to first create the same mailboxes on your destination, then use a mixture of mutt, getmail and scripting to transfer the mail. Mutt is a terminal based IMAP/POP client, which allows you to read and compose mail. getmail is a brilliant software which simply gets mail from server to client and still stores it in standard formats.

Assume that your user is named myuser and is located at /home/myuser. there is usually some folder named Maildir (or imap in case of DirectAdmin, but when you go in it, there is a list of mail users each having Maildir inside). This is the IMAP’s desired storage format (Maildir) also used by Dovecot.

Now install getmail on your destination and create a file ~/.getmail/getmailrc with the following content:

verbose = 1
delete = False

type = SimpleIMAPRetriever
server = sourceMailServer.com
username = srcUser
password = srcPass

type = Maildir
path = ~/imap/domain.com/srcUser/Maildir/

You have to update this file for every mailbox you’re going to migrate, and replace username, password and path accordingly. Then go to the path you describe, see if it exists (it should be your control panels default path or you’re not migrating correctly). If it does not exist, create the folder Maildir with 3 subfolders cur, new, tmp. You could also create the structure by using mutt instead of manually, as follows:

mutt -f imap://[email protected]

It then lists your messages and creates the folder structure for you.

Now run getmail, and wait for the magic to happen. It is definitely going to take some time if you have huge email base. You could automated this process for multiple accounts with a simple bash script. This whole process is way faster and easier than any other solutions.

Also keep in mind to use IMAP if applicable, otherwise you would only transfer Inbox. Don’t forget to ask your questions below.

1 comments On Migrating mail from one host to the other

Leave a reply:

Your email address will not be published.

Site Footer

Sliding Sidebar