Python API Wrapper Tutorial
This document introduces the Python API library which allows you to administer your MailStore Service Provider Edition via Python.
Installation
The API library is tested against Python 3.2 to Python 3.4. It is compatible with the 32bit and the 64bit versions of Python.
You can get your Python binary from the Python download page or you can install it using the package manager of you distribution.
Additionally you need the MailStore API library which has to be installed in your Python's site-packages directory. The location of the site-packages directory can be found with the following command
python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
Getting Started
Log in
The library can be imported with
>>>import mailstore
You are able to instantiate the class directly
>>>speClient = mailstore.spe.Client(username="admin", password="admin", host="127.0.0.1", port=8470)
or by using the with statement
>>>with mailstore.spe.Client(password="S3cR3t!", host="spe.domain.eu") as speClient: do_something()
Default values can be omitted.
Log out
When you prefer the first log in method, you have to log out afterwards manually. When using the with method, the log out is done automatically when exiting the with block.
>>>speClient.logout()
Simple calls
Simple calls will return immediately
>>>print(speClient.GetEnvironmentInfo()) {'antiXsrfToken': 'dUubPmGWEANyDxGbBvejCu6qSRUlkQYSiunQCGFkbWlu', 'logOutput': None, 'statusText': None, 'error': None, 'percentProgress': None, 'token': None, 'result': {'userName': 'admin', 'copyright': 'Copyright (c) 2005-2013 MailStore Software GmbH', 'systemProperties': {'totalPhysicalMemory': 2146947072, 'processors': ['Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz'], 'operatingSystem': 'Microsoft Windows Server 2012 Standard'}, 'serverName': 'win2012spe', 'version': '8.5.0.9288', 'licenseeName': 'MailStore Software GmbH', 'licenseeID': 1}, 'statusVersion': 2, 'statusCode': 'succeeded'}
When the statusCode is succeeded the information is stored in the result field. When the process has ended with another status, like failed or cancelled the diagnosis information is stored in the error field.
When there are no HTTP errors, the returned value is always a python dictionary.
>>>print(speClient.GetUserInfo(instanceID="test01",userName="admin")["result"]) {'userName': 'admin', 'distinguishedName': None, 'privileges': ['admin'], 'pop3UserNames': [], 'authentication': 'integrated', 'fullName': 'admin', 'emailAddresses': []}
Simple Examples
To get all user's detailled information you could
with mailstore.spe.Client("gerald", "s3cR3T1!", "speserver"): instance = "test01" for user in speClient.GetUsers(instance)["result"]: print(speClient.GetUserInfo(instance, user["userName"])["result"])