Send an email in Flask

Send emails from a Flask route with the Publiq Python SDK.

Install with pip install publiq and set PUBLIQ_API_KEY:

from flask import Flask, request
from publiq import Publiq

app = Flask(__name__)
publiq = Publiq()

@app.post("/send")
def send():
    email = publiq.emails.send({
        "from": "you@yourdomain.com",
        "to": request.json["to"],
        "templateKey": "welcome-email",
        "variables": {"first_name": "Ana"},
    })
    return {"id": email["id"]}

Best practices

  • Always call Publiq from the server — never expose the API key on the client.
  • Create the client instance once and reuse it across requests.
  • Prefer templateKey over inline HTML to keep content versioned.
  • Handle PubliqError (status/code); the SDK already retries transient errors with backoff.
  • Send from a verified domain — see Domains.

See also

Send an email in Flask — Publiq Docs