sendsend.email

Send email with Django

A server-side call to the SendSend API from your Django app.

  1. Create a test API key in the dashboard first: it never delivers real email. Switch to a live key once your domain is verified.
  2. Set SENDSEND_API_KEY in the environment and read it in settings.py with os.environ.
  3. Add this to mail/views.py:
import json, uuid, requests
from django.conf import settings
from django.http import JsonResponse

def send(request):
    to = json.loads(request.body)["to"]
    r = requests.post(
        "https://api.sendsend.email/v1/emails",
        headers={
            "Authorization": f"Bearer {settings.SENDSEND_API_KEY}",
            "Idempotency-Key": str(uuid.uuid4()),
        },
        json={"from": "Acme <hello@mail.acme.com>", "to": [to], "subject": "Hello from Django", "html": "<p>It works!</p>"},
        timeout=15,
    )
    return JsonResponse(r.json(), status=r.status_code)

Good to know