Django

Use the Posthawk Python SDK with Django views.

SDKdef send_email(request)

Send emails from a Django view.

Example

python
# views.py
from django.http import JsonResponse
from posthawk import Posthawk
from django.conf import settings

client = Posthawk(settings.POSTHAWK_API_KEY)

def send_email(request):
    result = client.emails.send(
        from_email="hello@yourdomain.com",
        to=request.POST["to"],
        subject=request.POST["subject"],
        html=request.POST["html"],
    )
    if result.error:
        return JsonResponse({"error": result.error.message}, status=500)
    return JsonResponse({"job_id": result.data.job_id})