Sending Transactional Email with Python
Send transactional email from Python in minutes with the Digitel Africa Mail SDK — install, authenticate, attach files and handle errors cleanly.
If your Python app needs to send order confirmations or password resets, you want a small, reliable client — not a pile of SMTP config. This guide uses the Digitel Africa Mail Python SDK end to end.
A single pip install, then send from any Python service or worker.
Install the SDK
The SDK supports Python 3.8+ and installs from PyPI.
pip install digitelAuthenticate
Read your API key from the environment and construct a client once, then reuse it.
import os
from digitel import Client
digitel = Client(api_key=os.environ["DIGITEL_API_KEY"])Send your first email
Call messages.send with your verified sender. It returns the queued message.
message = digitel.email.messages.send(
from_="[email protected]",
to=["[email protected]"],
subject="Your order is confirmed",
html="<h1>Thanks for your order</h1>",
)
print(message.id)Read the response
The response mirrors the REST API — a queued message with an id and timestamp.
{
"id": "msg_01HZY8QK3P4RN2",
"object": "email.message",
"status": "queued",
"to": ["[email protected]"],
"created_at": "2026-08-21T09:15:42Z"
}Attach files and send HTML
Attachments are a list of dicts. Render your HTML however you like — Jinja, an f-string, or a template engine.
message = digitel.email.messages.send(
from_="[email protected]",
to=["[email protected]"],
subject="Your invoice",
html=rendered_html,
attachments=[{"filename": "invoice.pdf", "content": pdf_bytes}],
)Handle errors
Catch ApiError and log the request_id; the SDK retries transient failures for you.
import logging
from digitel import ApiError
try:
digitel.email.messages.send(**payload)
except ApiError as err:
logging.error("Send failed: %s (%s)", err.message, err.request_id)Construct the client once, reuse it everywhere, and let the SDK handle retries. Your workers stay simple and your mail keeps flowing.
For webhooks, bounces and the full parameter list, see the documentation.