Migrating MS Exchange data to ONLYOFFICE

Introduction

This article describes how to transfer data from MS Exchange to ONLYOFFICE. Currently, the following data types are supported for transfer:

  • users,
  • mailboxes,
  • mail messages.

In the next releases, we are going to add support for the following data:

  • calendars,
  • contacts,
  • tasks.
This guide has been tested with MS Exchange 2016.

Export data from MS Exchange

Running the necessary service

First, make sure that the Microsoft Exchange Mailbox Replication (MSExchangeMailboxReplication) service is running. Run the following command in the cmd console:

Get-Service -name MSExchangeMailboxReplication

If the service you need is running, the command result will look like this:

Status   Name               DisplayName
------   ----               -----------
Running  MSExchangeMailb... Microsoft Exchange Mailbox Replication

Alternatively, go to the Windows Control Panel > Administrative Tools > Services, find the Microsoft Exchange Mailbox Replication service, and run it.

Assigning the rights

Assign the administrative rights to the user who is going to export the mailboxes from MS Exchange:

New-ManagementRoleAssignment -Role "Mailbox Import Export" -User <user name>

Where <user name> is the name of the user who is going to export the data. If you are going to do that yourself, assign this role to your account.

New-ManagementRoleAssignment -Role "Mailbox Import Export" -User John

After that, restart the Exchange Web Services (EWS) console with the administrator rights. To do that, right-click the EWS icon in the Start menu and select the Run as administrator option.

Running the script

Now download the script that will do everything you need for the correct export of the data from MS Exchange. The script is available via this link. Once downloaded, run it in the EWS console:

.\ExportExchangeData.ps1 -dir "C:\Temp"

Where .\ExportExchangeData.ps1 is the path to the script, and -dir "C:\Temp" is the path to the folder that will be used to export the files.

Note that while the script is running, the folder set in the -dir parameter will be shared with everyone. This is necessary for the correct work of the New-MailboxExportRequest command. After the script finishes its work, the sharing will be removed from the folder.

The folder with the exported files then needs to be transferred to the computer with ONLYOFFICE installed.

If you need to make sure that the created PST files have the correct data in them, you can use the free pst-viewer tool to do that.
Show what the ExportExchangeData.ps1 script does
Show the errors which might occur during the ExportExchangeData.ps1 script work

Import the MS Exchange data to ONLYOFFICE

Installing ONLYOFFICE Workspace Enterprise Edition and configuring Mail Server

Install the Docker version of ONLYOFFICE Workspace Enterprise Edition. This can be done by installing ONLYOFFICE Workspace Enterprise Edition using the script and selecting the Docker installation option. After that, set up the mail server as described in this article.

When connecting the domain, you will need to set the same domain as has been used for email messaging with MS Exchange, i.e., the domain from the user email addresses. If you need to change the domain name, you need to additionally edit the users.csv file, which was received in the step above, replacing all the entries for the old MS Exchange domain with the new one. This is done with the following command:
sed -i 's/exchange-domain.com/new-domain.com/g' users.csv
Where exchange-domain.com is the old domain name used with MS Exchange, and new-domain.com is the new one you are now going to use.
Downloading the script and installing or updating dependencies

Now you need to download and unpack the script that will perform the data import. This can be done using the following command:

wget -O "ImportExchangeData.tar" "https://help.onlyoffice.com/products/files/httphandlers/filehandler.ashx?action=view&fileid=5549294&version=0&doc=TWVPQks1aUo2MEprc0tkbUF6K2Y4Um1OSi9tTkd6V0lyTHFocG0xZHE0QT0_IjU1NDkyOTQi0" && tar -xvf ImportExchangeData.tar && cd ./Import

The command will download and unpack the file, creating the following folder structure:

Import
   |-lib
   |---create_users.py
   |---mbox2imap.py
   |---mapping.json
   |---pst2mbox.sh
   |---get-mailboxes.sh
   |---install-passfinder.sh
   |---ASC.Mail.PasswordFinder.tar
   |-ImportExchangeData.py
   |-requirements.txt

You will need Python v2.7 installed. It is often installed by default with various Linux distributions, but if it is missing, you will need to install it yourself. This is how it is done for Debian-based distributions:

# apt install python
# python -V
Python 2.7.12

Install the pip package manager, which is also necessary for the correct script work:

# apt install python-pip
# pip -V
pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)

And install the other required packages:

pip install -r requirements.txt
Running the script

Now you can run the script specifying the necessary parameters:

./ImportExchangeData.py -d "<portal domain>" -u "<portal administrator email>" -pw "<portal administrator password>" -f <path to the folder with the exported data>
If your portal is connected using HTTPS, you will additionally need to use the -s "https" parameter when running the code.

Replace the parameters in brackets with your own portal data and run the script:

./ImportExchangeData.py -d myportal.com -u "my.email.address@gmail.com" -pw "123456" -f /root/Temp/

Wait for the script to finish working. It might take some time depending on the number of users and the amount of their data.

Script work results

When the script finishes its work, the results will be the following:

  • the new portal users with the email addresses from the users.csv file will be created;
  • the mailboxes on the ONLYOFFICE Mail Server will be created; they will contain the mail messages from MS Exchange and will be connected in the ONLYOFFICE Mail module for the users listed in the users.csv file;
  • the results-ok.txt file will be saved to the Import folder; it will contain the list of all the user accounts from the users.csv file that were successfully created, and their passwords;
  • the result-err.txt file will be saved to the Import folder; it will contain the list of all the user accounts from the users.csv file that had problems when being imported and created;
  • the mailboxes.json file in the JSON format will be saved to the Import folder; it will contain the list of settings necessary to connect to the newly created mailboxes from third-party mail clients.
If you create mailboxes after the import, you can also get the settings necessary to connect them to third-party mail clients. Go to the ImportExchangeData.py folder and run the following command:
bash ./lib/get-mailboxes.sh -j
The mailboxes.json file will be overwritten with the new mailbox data.
Show what the ImportExchangeData.py script does
Article with the tag:
Browse all tags