Importing Multiple PST files in MailStore using Python script

The MailStore API can be utilised 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 as 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 show you how to configure and run Python scripts that have been provided by MailStore, and in this example specifically the bulkimport.py script to import a large number of PST files.

Step 1 Install Python for the first time

  1. Install the latest Python for Windows  from http://www.python.org/download/
  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
This image has an empty alt attribute; its file name is python-1.jpg

Step 2 Add MailStore Python API Wrapper

  1. Download the Python API Wrapper Library from https://help.mailstore.com/en/server/images/c/cc/Python-api-wrapper.zip
  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 similar path like the following returned:

    C:\Users\admin\AppData\Local\Programs\Python\Python39\Lib\site-packages

  3.  Navigate to this directory and create a new subdirectory called ‘mailstore’
  4. Unzip the Python API Wrapper Library you downloaded above into this ‘mailstore’ directory…
This image has an empty alt attribute; its file name is wrapper-files.jpg

Step 3 Using the MailStore ‘Bulk import’ Python Script

  1. Download the MailStore Python scripts from https://help.mailstore.com/en/server/images/2/29/Scripts.zip and unzip into a folder (for example C:\Mailstore Scripts)
  2. Edit C:\Mailstore Scripts\bulkimport.py in a text editor like notepad and change the following sections

# 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 a deepinvent folder )

# SERVER HOST

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 createUserFolders.py

# 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. Save the file with the changes

Create Template PST import job within MailStore

  1. Open MailStore Client and under the ‘Archive E-mail’ section create a new archive job (E-Mail-Files > Microsoft Outlook PST file)
  2. Choose ‘Single User’
  3. ‘Archive E-mail Stored in a PST File’  (enter a path of ‘c:\’ to be able to proceed)
  4. Click Next to skip the job options
  5. Click Next to  skip the target archives
  6. Name the job ‘templateBulkImportPST’
  7. Do not tick the option to run the job after finishing
  8. Click Finish to save the template job

Running the Script

  1. You will need to now create a folder for each of your mailstore users under your root path folder e.g.

C:\MailStore Scripts\rootpath\user1@domain.com\
C:\MailStore Scripts\rootpath\user2@domain.com\
C:\MailStore Scripts\rootpath\user3@domain.com\

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

  1. Finally to actually execute the script run the following command from c:\

Python c:\mailstore scripts\bulkimport.py

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

Special notes.

  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 user1.domain.com in this example
  4. Python should run from any path. this can be tested 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.

>>>