Package: python-mailcow
python-mailcowpython-mailcowallows you to interact with theMailCowAPI. It comes with a climailcow.
All arguments for the cli are generated by parsing your MailCow instance's OpenApi schema.Seedemo.mailcow.emailas OpenAPI scheme example.This means that you canadd,get,editanddeleteeverything that the MailCow API allows and changes to the API should be usable immediately....Famous last words... I know...BTW: The look and feel of the cli and configuration is inspired by thepython-gitlabproject.Installationfrom pypi:pip install python-mailcowfrom github:pip install git+https://github.com./derJD/python-mailcow.gitLocal Buildgit checkout mainpython setup.py sdistpip install dist/python-mailcow-9999.999.99.dev9.tar.gzUsagequick startGenerate a API token in the MailCow UImailcow --create-example-configEdit settings in~/.config/python-mailcow.cfgto match your MailCow UImailcow --helpshould now show all available options depending on your MailCow API versionConfigpython-mailcow read its settings from~/.config/python-mailcow.cfg.
An example configuration looks like this:[defaults]server=mailcow.example.comssl_verify=truetimeout=5[mailcow.example.com]url=https://mailcow.example.comtoken=123456-abcde-123456-abcde-123456ArgumentTypeDescriptionserverStringName of the section providing further server informationurlStringBase URL (MailCow UI location) for connection ie:https://demo.mailcow.emailtokenStringToken for API-Accessssl_verifyBooleanEnable/Disable ssl verificationtimeoutIntegerConnection timeoutCLIIf you installed python-mailcow for the first time you may run following
command and change the settings according to your needs:mailcow--create-example-configAfter that you should be able to run commands like these:mailcow alias get --all/--id 5mailcow alias add --address moep@example.com --goto goto@example.com --no-activemailcow alias delete --items 5mailcow --help:usage: test.py [-h] [--create-example-config] [--conf CONF] [--vertical] [--json] [--yaml] [--table] [--debug]
               {alias,app-passwd,bcc,dkim,dkim_duplicate,domain,domain-admin,da-acl,domain-policy,fwdhost,mailbox,oauth2-client,recipient_map,relayhost,resource,syncjob,tls-policy-map,transport,mailq,qitem,fail2ban,pushover,quarantine_notification,user-acl,logs,policy_bl_domain,policy_wl_domain,quarantine,rl-mbox,rl-domain,status,syncjobs,spam-score}
               ...

Interact with mailcows API.

positional arguments:
  {alias,app-passwd,bcc,dkim,dkim_duplicate,domain,domain-admin,da-acl,domain-policy,fwdhost,mailbox,oauth2-client,recipient_map,relayhost,resource,syncjob,tls-policy-map,transport,mailq,qitem,fail2ban,pushover,quarantine_notification,user-acl,logs,policy_bl_domain,policy_wl_domain,quarantine,rl-mbox,rl-domain,status,syncjobs,spam-score}

optional arguments:
  -h, --help            show this help message and exit
  --create-example-config
                        Create configuration file
  --conf CONF, -c CONF  Defaults to: ~/.config/python-mailcow.conf
  --vertical, -v        Print (table) results vertically
  --json, -j            Print results as JSON
  --yaml, -y            Print results as YAML
  --table, -t           Print results as Table
  --debug, -d           Enable debuggingmailcow alias add --help:usage: mailcow alias add [-h] [--active] [--address ADDRESS] [--goto GOTO] [--goto_ham] [--goto_null] [--goto_spam] [--sogo_visible]

optional arguments:
  -h, --help            show this help message and exit
  --active, --no-active
                        is alias active or not
  --address ADDRESS     alias address, for catchall use "@domain.tld"
  --goto GOTO           destination address, comma separated
  --goto_ham, --no-goto_ham
                        learn as ham
  --goto_null, --no-goto_null
                        silently ignore
  --goto_spam, --no-goto_spam
                        learn as spam
  --sogo_visible, --no-sogo_visible
                        toggle visibility in SoGoEditing alias' active status and visibility should look like this:mailcowaliasedit--items78--active--sogo_visible
+---------+----------------------------------------------------------------------------------------+-------------------------------------------+|type|log|msg|+---------+----------------------------------------------------------------------------------------+-------------------------------------------+|success|['mailbox','edit','alias',{'id':['78'],'active':'1','sogo_visible':'1'},None]|['alias_modified','example@example.com']|+---------+----------------------------------------------------------------------------------------+-------------------------------------------+pythonClassMailCow()Connect to MailCow instance defined in config file and
interact via API RequestsMailCow()takes the same arguments as listed inConfigand one additional optional argument:ArgumentTypeDescriptionconfStringPath to config fileEvery argument is optional and accessible as attribute.AttributesTypeDescriptiondatadict/NoneStore API responses here and display response via methodsas_json,as_yaml,as_tablejsondict/NoneStore payload for API requests hererequest_urlstring{url}/api/v1sessionobjectSession used for requestsschemadictSchema retrieved from MailCows OpenApiendpointsdictAll endpoints from filtered fromschemaMethodendpoint(endpoint)Returns specific endpoint asdictorNoneArgumentTypeDescriptionendpointstringName of the endpoint. ie"alias"or"mailbox"MethoddeleteRequest(section, items)Send delete requestArgumentTypeDescriptionsectionstringsection aka last part of the url. iealiasitemslistList of items to delete. ie:['5']MethodgetRequest(section)Send get requestArgumentTypeDescriptionsectionstringsection aka last part of the url. iealias/allMethodaddRequest(section, json)Send add requestArgumentTypeDescriptionsectionstringsection aka last part of the url. iealiasjsondictattributes send as payload. ie{'active': '1', 'address': 'example@example.com'}MethodeditRequest(section, items, attr, action)Send edit requestArgumentTypeDescriptionsectionstringsection aka last part of the url. iealiasitemslistitems send as payload .ie['5']or['domain.tld']attrdictattributes send as payload. ie{'active': '1', 'address': 'example@example.com'}actionstringaction send as payload. only needed bymailqsection .ieflushMethodas_json()Returndataas jsonMethodas_yaml()Returndataas yamlMethodas_table(vertical)Returndataas table.verticalexpects booleanArgumentTypeDescriptionverticalboolEnable/Disable vertical print ofdata. Defaults toFalseExamplemoo=MailCow()logs=moo.getRequest(section='logs/api/5')moo.data=logsprint(moo.as_table())# returns:# +------------+----------------------------------+--------+-----------+------+# |    time    |               uri                | method |   remote  | data |# +------------+----------------------------------+--------+-----------+------+# | 1611102437 |      /api/v1/get/logs/api/5      |  GET   | xx.x.xx.x |      |# | 1611096182 | /api/v1/get/rl-mbox/xx@examp.com |  GET   | xx.x.xx.x |      |# | 1611087846 | /api/v1/get/rl-mbox/xx@examp.com |  GET   | xx.x.xx.x |      |# | 1611087808 |    /api/v1/get/logs/dovecot/5    |  GET   | xx.x.xx.x |      |# | 1611087797 | /api/v1/get/syncjobs/all/no_log  |  GET   | xx.x.xx.x |      |# +------------+----------------------------------+--------+-----------+------+LicenseCode released underGNU General Public License v3.0 or laterAuthorderJD