Migrating MS Exchange data to ONLYOFFICE

Introduction

This article will show how you can transfer the 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 the 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 of all you need to make sure that the Microsoft Exchange Mailbox Replication (or MSExchangeMailboxReplication) service is launched. Run the following command in cmd console:

Get-Service -name MSExchangeMailboxReplication

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

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

Or you can go to the Windows Control Panel - Administrative Tools - Services, find the Microsoft Exchange Mailbox Replication and run it.

Assigning the rights

Assign the administrative rights to the user who is going to do the export of the mail boxes from MS Exchange:

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

Where <user name> is the user name who is going to export the data. If you are going to do that yourself, then 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. This is done clicking the EWS icon in the start menu with the right mouse button and selecting the Run as administrator option.

Running the script

Now download the script which will do everything you need for the correct export of the data from MS Exchange. The script is available here. 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 which will be used to export the files.

Please note that during the script work the folder set in the -dir parameter will be shared for 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 need 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 configure Mail Server

Install the Docker version of ONLYOFFICE Workspace Enterprise Edition. This can be done installing ONLYOFFICE Workspace Enterprise Edition using the script and selecting the Docker installation variant. After that set up the mail server as written here.

When connecting the domain, you will need to set the same domain as has been used for email messaging with MS Exchange (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 script and installing/updating dependencies

Now you need to download and unpack the script which will do the data import process. This can be done using the command:

wget -O "ImportExchangeData.tar" "https://help.onlyoffice.co/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 in case it is missing, you will need to install it yourself. This is how it is done for Debian-based distributions:

# apt install python# python -VPython 2.7.12

Install the pip (package manager), 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 need additionally 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 does everything it is intended for, the results will be the following:

  • the new portal users with the email adresses from the users.csv file will be created;
  • the mailboxes at the ONLYOFFICE Mail Server will be created, which will have the mail messages from MS Exchange and will be connected in the ONLYOFFICE Mail module for the users listed in the users.csv file;
  • results-ok.txt file will be saved to the Import folder, it will contain the list of all user accounts from the users.csv file and their passwords, which were successfully created;
  • result-err.txt file will be saved to the Import folder, it will contain the list of all user accounts from the users.csv file, which had problems when they were imported and created;
  • 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 the third-party mail clients.
If you create some mailboxes after the import, you can also get the settings necessary to connect them to the third-party mail client programs. Go to the ImportExchangeData.py folder and run the command:
bash ./lib/get-mailboxes.sh -j
The mailboxes.json file will be overwritten with the new mailboxes data.
Show what the ImportExchangeData.py script does

Host ONLYOFFICE Workspace on your own server

Article with the tag:
Browse all tags