MailStore Python script to import multiple PST files

MailStore APi can be used to automate tasks that would be laborious to do manually. One such task is importing a large number of PST files for multiple users. A good example of this is when you want to archive pre-existing Office 365 Archives. Unfortunatly these cannot be collected using the mailbox collection method but instead, need to be first exported to PST files for each user.

The following steps will guide you through using the example python script can be used to import a large number of PST files into MailStore Server.

Step 1 Install Python for the first time

  1. Install the latest Python for Windows  from
  2. Tick the option to add Python 3.9 to the System PATH
  3. Choose ‘Install Now’

4. At the end of the install choose the option to support long paths

Step 2 Add MailStore Python API Wrapper

  1. Download the Python API Wrapper Library from
  2. Find your  Python site-packages directory using the following command at the Windows command Prompt (this is a single command)

python -c “from distutils.sysconfig import get_python_lib; print(get_python_lib())”

you should see a simular path lik ethe following returned


3. Navigate to this directory and create a new subdirectory called ‘mailstore’

Unzip the Python API Wrapper Library you downloaded above into this ‘mailstore’ directory

Step 3 Using the MailStore ‘Bulk import’ Python Script

  1. Download the MailStore Python scripts from and unzip into a folder (for example C:\Mailstore Scripts)
  2. Edit C:\Mailstore Scripts\ in text editor like Notepad
  3. Change the following sections and save the file

# SERVER CMD on x64 OS
MAILSTORECMD = r”C:\Program Files (x86)\MailStore\MailStore Server\MailStoreCmdSilent.exe”

(Note this path in the script is incorrect for MailStore v13 and points to an incorrect deepinvent folder )

HOST = “your server address”

# USER and PASS of an administrator
USER = “admin”
PASS = “yourpassword”

# location of the folders containing the user’s pst/emlmsg/mbox files
# has to be the same as in
# please note the ‘r’ in the beginning, this indicates a raw-string, \ will not be interpreted
# so, just leave the ‘r’ in front

rootpath = r”C:\MailStore Scripts\rootpath”

  1. Within MailStore Server create a new archive job ( E-Mail-Files > Microsoft Outlook PST file) in MailStore
  • Choose ‘Single User’
  • ‘Archive E-mail Stored in a PST File’  (enter a path of ‘c:\’ to be able to proceed)
  • Click next  to skip the job options
  • Click Next to  skip the target archives
  • Name the job ‘templateBulkImportPST’
  • Do no not tick the option to run the job after finishing!
  • Click Finish to save the template Job
  1. using the Windows file manager Create a folder for each of your mailstore users under your root path folder e.g.

C:\MailStore Scripts\rootpath\\
C:\MailStore Scripts\rootpath\\
C:\MailStore Scripts\rootpath\\

Each folder should contain any PST files to be imported for that user ( these can have any name)

  1. Execute the script run the following command from c:\

Python c:\mailstore scripts\

This should run through each user and find the PST files and import them


  1. You must have a copy of Outlook running on the PC
  2. A log file for each user is created under c:\mailstore scripts\rootpath\ this will help with debugging
  3. A MailStore user archive must exist for each user with exactly the same name as the rootpath folder e.g in this example
  4. Python should run from any path. Test by running the command  ‘python’ at a command prompt you should see…

C:\MailStore Scripts>python

Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec  7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32

Type “help”, “copyright”, “credits” or “license” for more information.