Difference between revisions of "Scripting"

[unchecked revision][unchecked revision]
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
With the [[MailStore Server Management Shell]] as well as the [[MailStore Server Administration API]] MailStore Server offers multiple methods of automating tasks by using scripts. In this scripting area we have put together scripts that provide solutions for use-cases we have often been asked for.
 
  
This article describes needed steps of preparation as well as how to execute the scripts.
+
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.
  
= Download the script package =
+
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.
Download the [[Media:MailStoreScripts.zip‎|script package]] and unzip it using your favourite unzip software, then review the documentation below to use the scripts. Note that you will need to modify the scripts to tailor them to your particular environment.
 
  
= Using Windows Batch Scripts =
+
<p class=msnote>'''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.</p>
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.
+
 
 +
= 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 [[Email_Archiving_with_MailStore_Basics#Viewing_the_Command_Line|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.
 +
 
 +
* [[Windows Batch Scripts]]
  
 
= Using Python Scripts =
 
= Using Python Scripts =
  
== Preparation ==
+
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.
In order to execute Python scripts from our [[Media:MailStoreScripts.zip‎|script package]] your need to install the Python runtime. The Windows Installer of the Python runtime can be downloaded from http://www.python.org. For Linux operating systems please follow the instructions of your distributor's package manager to install the Python runtime. The API Wrapper is compatible to Python 3.2 and Python 3.3.
 
  
Our [[Media:MailStoreScripts.zip‎|script package]] includes a version of the MailStore Server Administration API Python wrapper. Therefore after downloading the package you just need to extract the content into a directory on your local hard disk.
+
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 [http://www.python.org 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.
  
== Executing Python Scripts ==
+
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.
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 saying ''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.
 
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.
  
== Changelog ==
+
* Python API Wrapper Tutorial ''(in preparation)''
 +
* [[Media:MailStoreScripts.zip?|Script Package]]
 +
* [[Python Scripts]]
 +
 
 +
= 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.
  
2013-04-17 New: [[Python_Scripts#updateUserNames.py|updateUserNames.py]], [[Python_Scripts#mergeFolders.py|mergeFolders.py]]
+
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 [https://www.microsoft.com/en-us/download/default.aspx Microsoft Download Center] free of charge.
  
2013-06-25 Bugfix: MailStoreApi.RebuildStoreIndex was not working properly
+
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.
  
2013-09-17 New: [[Monitoring|check_mailstorelicence.py]]
+
* [[PowerShell API Wrapper Tutorial]]
 +
* PowerShell Scripts ''(in preparation)''
  
 
[[de:Scripting]]
 
[[de:Scripting]]
 +
[[en:Scripting]]

Revision as of 10:31, 21 February 2014


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.