Python

Send an email from Python with the notix-sdk package.

Send your first email from Python with notix-sdk, the official SDK. It needs Python 3.10 or newer. You install notix-sdk and import notix.

Prerequisites

  1. Install the SDK

    pip install notix-sdk
    
  2. Set your API key

    The client reads NOTIX_API_KEY when you do not pass a key.

    NOTIX_API_KEY=notix_12345
    
  3. Send an email

    Pass a plain dict, so you can use the from key.

    from notix import Notix
    
    notix = Notix()  # reads NOTIX_API_KEY
    
    data, _ = notix.emails.send(payload={
        "from": "Acme <receipts@acme.com>",
        "to": "maria@example.com",
        "subject": "Your receipt for order 4471",
        "html": "<p>Thanks for your order, Maria.</p>",
        "text": "Thanks for your order, Maria.",
    })
    
    print("Sent", data["emailId"])
    
  4. Handle errors

    By default the client raises NotixHTTPError when the API answers with an error. The exception carries the status and the error body.

    from notix import Notix, NotixHTTPError
    
    notix = Notix()
    
    try:
        data, _ = notix.emails.send(payload={
            "from": "receipts@acme.com",
            "to": "maria@example.com",
            "subject": "Your receipt",
            "html": "<p>Thanks for your order.</p>",
        })
    except NotixHTTPError as err:
        print(err.status_code, err.error.get("code"), err.error.get("message"))
    

    Prefer not to raise? Create the client with Notix(raise_on_error=False). Every method then returns (data, error), and error is set when the call failed.

Next steps

  • Send many emails at once with batch sending: notix.emails.batch(payload=[...]).
  • Add files with attachments.
  • Make retries safe with idempotency keys: options={"idempotency_key": "order-4471-receipt"}.
  • Hear about deliveries and bounces with webhooks.
Open in ClaudeOpen in ChatGPT