Scripting
Starting with version 7, MailStore Server provides powerful interfaces, such as the MailStore Server Management Shell and the MailStore Server Administration API, that can be used to automate many tasks through scripts. This makes it possible to realize scenarios that would be difficult or impossible to implement through the GUI. Furthermore, scripting allows to integrate MailStore Server in existing workflows or business processes.
This article exemplifies the usage of the MailStore Server Administration API in several scripting languages. In our scripting section we assorted various scripts that make use of the demonstrated techniques and solve frequently posed problems. These scripts can be used freely and may be adapted to a specific environment or serve as a basis for further solutions.
Important Notice: The scripting code published in this section must be considered as reference and example implementations. Please refer to the licensing terms in the respective script files for details.
Using Window Batch Scripts
For simple tasks, such as bulk import or export of PST files, Window batch scripts may also be used. Usually, these scripts do not control MailStore Server through the MailStore Server Administration API but through the command line interpreter.
Before you are able to execute Windows batch scripts on the command line cmd.exe, you need to open the script file in a text editor such as Notepad. Adjust the configuration variables above the DON'T CHANGE ANYTHING BEYOND THIS LINE line to your local environment. Please take care not to change any single or double quotes.
Available Windows Batch Scripts
File Name | Description |
---|---|
bulkImportPST.bat | Import multiple PST files from a given directory into the archive of a the given MailStore user. |
bulkImportMBOX.bat | Import multiple MBOX files from a given directory into the archive of a the given MailStore user. |
bulkExportPST.bat | Export of all archives into multiple PST files seperated by MailStore users. |
bulkDeleteUsers.bat | Delete all MailStore users except the default admin user 'admin'. |
Using Python Scripts
Complex processes can more easily be automated with a higher level scripting language than simple Windows batch scripts. As a widely used, platform independent and easy to learn but powerful scripting language, Python is well suited to control MailStore Server through the MailStore Server Administration API.
To be able to execute Python scripts you need to install the Python runtime. The Windows installer of the Python runtime can be downloaded from Python.org. For Linux operating systems, please follow the instructions of your distributor's package manager to install the Python runtime.
For executing our scripts, a version of the Python API Wrapper is required. Installation instructions for the wrapper are available in the corresponding section of the Python API Wrapper Tutorial.
In order to execute Python scripts, you have to open the script file you want to execute with IDLE (shipped with Python's Windows installer) and adjust the configuration section above the line stating DON'T CHANGE ANYTHING BEYOND THIS LINE. Please take care not to change any double or single quotes.
To execute the script, click on Run > Run Module or press the F5-key in IDLE. A new window pops up where you can follow the standard output of the script and see possible execution errors.
If you are planning to write your own scripts in Python to automate MailStore Server tasks, the Python API Wrapper Tutorial offers a good starting point. Otherwise, if you just want to make use of the provided Python Scripts, you can download them from here.
Available Python Scripts
File Name | Description |
---|---|
mergeFolders.py | Merge sub folder branches. Often needed after archiving from multiple PSTs for one user. |
createUserFolders.py | Create folders in file system based on MailStore user names. Can be used in preparation of bulk imports of EML, MSG or PST files. |
check_mailstorelicense.py | Nagios/Icinga plugin for monitoring available licenses. See Monitoring for further details. |
check_mailstore.py | Nagios/Icinga plugin for monitoring recent results. See Monitoring for further details. |
Using PowerShell Scripts
As the standard shell that is shipped with every newer version of Windows, the .NET framework based Windows PowerShell is also well suited to control MailStore Server through the MailStore Server Administration API.
The MailStore PowerShell API Wrapper and the scripts are compatible with Windows PowerShell 3.0 and higher. Depending on the version of Windows, the Windows PowerShell has to be installed separately; it can be downloaded at the Microsoft Download Center free of charge.
If you want to implement your own scripts to automate MailStore Server tasks, the PowerShell API Wrapper Tutorial is ideal to start with. If you just want to use the scripts offered by MailStore, you can simply navigate to that section directly.