Framework Integrations
Django integration
Send transactional email with Sendery templates through Django’s email backend.
pip install sendery-djangoRequirements
Django 5.2 and Python 3.10+.
Configure the backend
Publish a welcome template with name and action_url variables, and create a project API key. Store it as SENDERY_API_KEY on your server. Add the backend and key to your Django settings.
# settings.py
import os
EMAIL_BACKEND = "sendery_django.backend.EmailBackend"
SENDERY_API_KEY = os.environ["SENDERY_API_KEY"]Send an email
Use TemplateEmail with one recipient. Its sendery_receipt contains the accepted email’s ID and status. Ordinary EmailMessage objects, attachments, and cc or bcc recipients are not supported. Set the sender in your Sendery project.
from sendery_django import TemplateEmail
email = TemplateEmail(
to="[email protected]",
template="welcome",
data={"name": "Alex", "action_url": "https://example.com/start"},
)
email.send(fail_silently=False)
print(email.sendery_receipt["id"])Password resets
Publish a password-reset template with name and action_url. Use SenderyPasswordResetForm with Django’s authentication views. Add these routes to your urlpatterns and provide Django’s standard password-reset HTML pages under templates/registration/. If the routes already exist, change only the reset view’s form_class.
# urls.py
from django.contrib.auth import views as auth_views
from django.urls import path
from sendery_django.forms import SenderyPasswordResetForm
urlpatterns = [
path("password-reset/", auth_views.PasswordResetView.as_view(
form_class=SenderyPasswordResetForm,
), name="password_reset"),
path("password-reset/done/", auth_views.PasswordResetDoneView.as_view(),
name="password_reset_done"),
path("reset/<uidb64>/<token>/", auth_views.PasswordResetConfirmView.as_view(),
name="password_reset_confirm"),
path("reset/done/", auth_views.PasswordResetCompleteView.as_view(),
name="password_reset_complete"),
]Retry a send
Keep fail_silently=False to receive SenderyError on API failures. The backend makes one attempt. In a background task, save the recipient, variables, and idempotency_key before sending and reuse them for retries.
# Use the same saved recipient, variables, and event key on every attempt.
email = TemplateEmail(
to="[email protected]",
template="welcome",
data={"name": "Alex", "action_url": "https://example.com/start"},
idempotency_key="welcome-123",
)
email.send(fail_silently=False)