Skip to content

Python wrapper interacting with MailCow API

License

Notifications You must be signed in to change notification settings

derJD/python-mailcow

Repository files navigation

python-mailcow

PyPI versionPyPI downloadspylint

python-mailcow allows you to interact with the MailCow API. It comes with a cli mailcow. All arguments for the cli are generated by parsing your MailCow instance's OpenApi schema.

See demo.mailcow.email as OpenAPI scheme example.

This means that you can add, get, edit and delete everything 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 the python-gitlab project.

Installation

  • from pypi: pip install python-mailcow
  • from github: pip install git+https://github.com./derJD/python-mailcow.git

Local Build

git clone https://github.com/derJD/python-mailcow.git cd python-mailcow pip install .

Usage

quick start

  • Generate a API token in the MailCow UI
  • mailcow --create-example-config
  • Edit settings in ~/.config/python-mailcow.cfg to match your MailCow UI
  • mailcow --help should now show all available options depending on your MailCow API version

Config

python-mailcow read its settings from ~/.config/python-mailcow.cfg. An example configuration looks like this:

[defaults]server = mailcow.example.com ssl_verify = true timeout = 5 [mailcow.example.com]url = https://mailcow.example.com token = 123456-abcde-123456-abcde-123456
ArgumentTypeDescription
serverStringName of the section providing further server information
urlStringBase URL (MailCow UI location) for connection ie: https://demo.mailcow.email
tokenStringToken for API-Access
ssl_verifyBooleanEnable/Disable ssl verification
timeoutIntegerConnection timeout

CLI

If you installed python-mailcow for the first time you may run following command and change the settings according to your needs:

mailcow --create-example-config

After that you should be able to run commands like these:

  • mailcow alias get --all/--id 5
  • mailcow alias add --address moep@example.com --goto goto@example.com --no-active
  • mailcow alias delete --items 5

mailcow --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 debugging

Documentation

License

Author

About

Python wrapper interacting with MailCow API

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published