Skip to main content

Official Python client SDK for the Mailfold API

Project description

mailfold-client

Official Python client SDK for Mailfold — a self-hosted webmail/admin backend. This package wraps Mailfold's machine-to-machine REST API (mail sending, folders, messages, search, attachments, and flags) behind a small, typed Python client.

This is the official client SDK for the Mailfold project. It has zero third-party runtime dependencies — it only uses Python's standard library (urllib.request, json).

Install

pip install mailfold-client

(Import name is mailfold, package name on PyPI is mailfold-client.)

Authentication

Every request is authenticated with a per-mailbox API key issued by your Mailfold instance — an opaque bearer token that looks like mf_live_<kid>_<secret>. Treat it as an opaque string; never parse it.

Quickstart

from mailfold import Client, MailfoldAPIError

client = Client(base_url="https://mail.example.com", api_key="mf_live_xxxxxxxxxxxxxxxx_yyyyy")

try:
    # Send a message (from address is always the mailbox bound to the API key)
    result = client.send(
        to=["alice@example.com"],
        cc=["bob@example.com"],
        subject="Hello from mailfold-client",
        text="Plain text body",
        html="<p>HTML body</p>",
    )
    print(result.status)  # "sent"

    # List folders
    for folder in client.folders():
        print(folder.name, folder.attributes)

    # List recent messages in a folder
    headers = client.messages(folder="INBOX", limit=20)
    for msg in headers:
        print(msg.uid, msg.subject, msg.seen)

    # Fetch a single full message
    if headers:
        msg = client.message(folder="INBOX", uid=headers[0].uid)
        print(msg.text, msg.attachments)

        # Download the first attachment, if any
        if msg.attachments:
            att = client.attachment(folder="INBOX", uid=msg.uid, index=0)
            print(att.filename, att.content_type, len(att.data))

    # Search
    results = client.search(folder="INBOX", q="invoice")
    print([m.subject for m in results])

    # Flag a message as seen
    if headers:
        client.set_flag(folder="INBOX", uid=headers[0].uid, flag="seen", set=True)

        # Delete a message
        client.delete_message(folder="INBOX", uid=headers[0].uid)

except MailfoldAPIError as e:
    print(e.status_code, e.message, e.retry_after)

API surface

Method Endpoint Scope
client.send(to=, cc=, bcc=, subject=, text=, html=) POST /api/v1/mail/send mail:send
client.folders() GET /api/v1/mail/folders mail:read
client.messages(folder=, limit=) GET /api/v1/mail/messages mail:read
client.message(folder, uid) GET /api/v1/mail/message mail:read
client.delete_message(folder, uid) DELETE /api/v1/mail/message mail:write
client.search(folder=, q=) GET /api/v1/mail/search mail:read
client.attachment(folder, uid, index) GET /api/v1/mail/attachment mail:read
client.set_flag(folder, uid, flag, set) POST /api/v1/mail/flag mail:write

Error handling

Any non-2xx response raises mailfold.MailfoldAPIError with:

  • status_code — the HTTP status code (400, 401, 403, 413, 429, 502)
  • message — the server's "error" message string
  • retry_after — the Retry-After header value in seconds, when present (429 responses)

A mailfold.MailfoldConnectionError is raised if the request cannot reach the server at all (network failure, DNS, timeout, etc).

About Mailfold

Mailfold is a self-hosted webmail/admin backend. See the main project at https://github.com/isi1988/Mailfold.

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mailfold_client-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mailfold_client-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file mailfold_client-0.1.0.tar.gz.

File metadata

  • Download URL: mailfold_client-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for mailfold_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cdcbf4667ec5e776b55cc7b3da561e651fb513df326b49c6bf726f4f5850c687
MD5 0d742200c407fd5f4bf76b84f73d8792
BLAKE2b-256 3e4c6d742d6d3e9e81b03fa4c85b44def1a5a75ebd532fe3a32c09c3af252c34

See more details on using hashes here.

File details

Details for the file mailfold_client-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mailfold_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 15e298ffb3751d05cdbbf3c3150fe00ea25c760845142aea62606d43e3e6817d
MD5 8f5522ba7dda09b4f12b0953a36b5f46
BLAKE2b-256 6d03f2853b91dd66999a0831a560155b6d3c4b0dda397393c2442ef59366e644

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page