Send an email in Django

Call Publiq from a Django view to send transactional emails.

Create the client once (module level) and use it in the view:

from django.http import JsonResponse
from publiq import Publiq

publiq = Publiq()  # reads PUBLIQ_API_KEY

def send_welcome(request):
    email = publiq.emails.send({
        "from": "you@yourdomain.com",
        "to": request.POST["email"],
        "templateKey": "welcome-email",
        "variables": {"first_name": request.POST.get("name", "there")},
    })
    return JsonResponse({"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 Django — Publiq Docs