How to migrate emails from cPanel to Virtualmin

Cpanel to Virtualmin email migration

If you’re looking to move your emails from a cPanel server to Virtualmin, you’ve come to the right place. I’ve been through this process and want to share the steps that worked for me. You might run into a few hiccups along the way, but don’t worry—I’ll cover those too.

Before we dive in, make sure you’ve got SSH access to both servers and your SSH key ready. If you’re not using keys, that’s cool; you can use your password instead. Also, you’ll need doveadm, which usually comes with Dovecot, on your Virtualmin server.

Step 1: Copying Your Emails Over
Before you start, log into your Virtualmin server with a user that has enough rights to manage files—being a sudoer will make things smoother. Now, let’s get those emails moving with rsync. Keep in mind, the email paths aren’t the same in cPanel and Virtualmin, so you’ll want to double-check those. Swap in your own {cpanel_server_ip}, {user}, and {domain} where needed.

Using an SSH key:

sudo rsync -avz -e "ssh -i /path/to/your_ssh_key" --exclude 'dovecot*' root@{cpanel_server_ip}:/home/{user}/mail/{domain}/{user}/ /home/{user}/homes/{user}/Maildir

Prefer a password? No problem, just run this and type it in when asked:

sudo rsync -avz -e "ssh" root@{cpanel_server_ip}:/home/{user}/mail/{domain}/{user}/ /home/{user}/homes/{user}/Maildir

Step 2: Fixing Permissions
Next, we need to make sure the files we just moved have the right owner. Swap out {user} and {domain} with your info again.

sudo chown -R {user}@{domain}:{user} /home/{user}/homes/{user}/Maildir

Step 3: Setting the Right Access
Let’s set the permissions so that files and folders are accessible as they should be.

sudo find /home/{user}/homes/{user}/Maildir -type f -exec chmod 644 {} \;
sudo find /home/{user}/homes/{user}/Maildir -type d -exec chmod 700 {} \;

Step 4: Getting Those Emails to Show Up
Here’s where it gets interesting. You might notice that not all emails are showing up in Usermin, even though they’re right there on the server. Don’t panic! We’re going to tell Dovecot to re-index everything.

sudo doveadm index -u {user}@{domain} '*'

Still not seeing them? Let’s force Dovecot to resync:

sudo doveadm -D force-resync -u {user}@{domain} '*'

Step 5: The Magic Touch
If emails are still playing hide and seek, here’s a neat trick. By creating and deleting a file in each folder, we can nudge the system to refresh itself.

sudo find /home/{user}/homes/{user}/Maildir -type d -name cur -exec sh -c 'f="{}/.refresh"; touch "$f" && rm -f "$f"' \;

And that’s it! Log into Usermin and check out your emails—they should all be there now.

Remember, replace {user}, {domain}, and {cpanel_server_ip} with your actual details. This isn’t a formal guide—it’s based on real experience, so your mileage may vary. If you hit a snag, the rsync, Dovecot, and mail client communities are great places to ask for help.

Good luck with your migration!