CategoriesGuides & Hacks

Exporting Email Users from cPanel for Microsoft 365 Migration: A Step-by-Step Guide

So, you’re ready to make the leap from cPanel’s email service to Microsoft 365. Excellent choice! With Microsoft 365, you’ll get better collaboration tools, improved security, and the ability to access your emails from pretty much anywhere. But before you dive into the migration process, there’s one critical task to tackle: exporting your email accounts into a CSV file. Why? Because it lets you use Microsoft 365’s import tool and migration wizard to sync your mailbox accounts before you even think about changing MX records. This way, you can avoid those panicked “Where are my emails?!” calls from your users. You could do this one by one, but that’s just not my style (also, I have 79 users to migrate…).

Getting Started

First things first, you’ll need console access to your server. If you’re already nodding along, fantastic! Fire up your terminal and connect to your server via SSH using a command like this:

ssh yourusername@yourserverip

Make sure you have root or sudo privileges because we’ll need to poke around in some directories that aren’t accessible to regular users. If you don’t have this, you better grab a coffee for your server administrator before you ask for some help!

Once you’re in, navigate to the home directory where all the magic happens:

cd /home

Here, you’ll see a list of user directories – each corresponding to a cPanel account. Navigate into the user’s etc directory where email account information is stored:

cd username/etc

If you have multiple domains or subdomains, you’ll find separate folders for each. Navigate to the appropriate domain folder to locate the passwd file:

cd domain.com

For example, if your username is exampleuser and your domain is example.com, the path would be:

cd /home/exampleuser/etc/example.com

Extracting the Email Account Information

Now comes the fun part: grabbing those email accounts. To extract the email addresses from the passwd file, use the following command:

awk -F: '{print $1}' passwd

This command pulls out all email accounts listed in the passwd file. You’ll see a list that includes the usernames associated with the email addresses. It’s important to note that, despite the name, the passwd file doesn’t contain any passwords – only the email addresses and some other metadata. So, no worries about exposing sensitive information here!

Formatting the Data for CSV

We’ll use a quick awk command to format the output into something that looks more like, well, a spreadsheet. You know, those things everyone loves to hate:

awk -F: '{print $1 "@example.com"}' passwd > email_accounts.csv

This command transforms the raw data into a simple list of email addresses and saves it to a file called email_accounts.csv. You should now have a neat list of all email addresses in your domain.

A Quick Detour to Nano

Let’s take a look inside that CSV file using nano. Open up the file:

nano email_accounts.csv

You’ll see your list of email addresses in all its glory. You can add headers, or modify the file in any way you need. Once you’re happy with your file, save it by pressing CTRL + O, then exit nano with CTRL + X.

Getting the File to Your Local Machine

Now that our CSV file is prepped and ready, we need to get it onto your local machine. This is where WinSCP comes in handy. Open up WinSCP, connect to your server using the same credentials you used for SSH, and navigate to the directory where your CSV file is located (e.g., /home/exampleuser/etc/example.com). Simply drag and drop the file over to your local machine.

Preparing for Migration

With your CSV file on your local machine, you’ve completed the first and most important step in your migration journey – gathering a list of all your email accounts. This CSV file will be your go-to resource when you’re ready to set up these accounts on Microsoft 365.

While the actual migration process involves a few more steps, like creating user accounts and syncing mailboxes, we’re not covering that part here. For now, you’ve got the essential information you need to start planning your transition. Happy migrating!

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome content in your inbox

We don’t spam! Read our privacy policy for more info.

Leave a Reply

Your email address will not be published. Required fields are marked *