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

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 simular path lik ethe 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’

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 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 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 )

# 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. 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\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. 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

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

>>>