Scripting

Revision as of 20:41, 25 June 2014 by Dweuthen (talk | contribs)


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.

API Wrapper

As an HTTPS-based interface it is possible to use the MailStore Server Administration API with basically any programming or scripting language that supports web requests. To simplify script development, an API wrapper should be used that encapsulates API communication. Using such a wrapper, script developers can concentrate on the desired script functionality and profit from easier debugging as well as from somewhat standardized scripts.

The Python and PowerShell scripts offered by MailStore use implementations of such API wrappers that can be used as a reference. These wrappers are themselves written in the respective scripting language (Python 3.x or Powershell 3.0) and contain comments and in-line help for better comprehension. The corresponding articles offer more details on their functionality.

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.

Using Python 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. Our script package includes a version of the MailStore Python API Wrapper. Therefore, after downloading the package, you just need to extract the content into a directory on your local hard disk. The API wrapper is compatible to Python 3.2 and Python 3.3.

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.

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.