A simple wrapper around django-ses to receive and persist sns event data.
Records mail delivery in the SESMailDelivery
model and updates the state if a matching SNS notification is received.
- Django version 3.2+
- A PostgreSQL Database
-
Add
ses_sns_tracker
to your INSTALLED_APPS setting like this:INSTALLED_APPS = [ # ... 'ses_sns_tracker', ]
-
Run
python manage.py migrate
to create the models. -
Setup
django-ses
-
Add the webhook view to
urls.py
:from django_ses.views import SESEventWebhookView urlpatterns = [ # ... path('ses-events/', SESEventWebhookView.as_view(), name='handle-event-webhook'), # ... ]
-
(Optional) Use
ses_sns_tracker.backends.SESSNSTrackerBackend
as your default email backend:EMAIL_BACKEND = 'ses_sns_tracker.backends.SESSNSTrackerBackend'
This way all emails will be sent via the Amazon SES API.
-
(Optional) Send an email via the
SESMailDelivery
manager (doesn't requireSESSNSTrackerBackend
as the default mail backend):from django.core.mail import EmailMessage from ses_sns_tracker.models import SESMailDelivery message = EmailMessage( subject='email subject', body='email body', from_email='[email protected]', to=['[email protected]'], ) SESMailDelivery.objects.create_message(message, fail_silently=False, fake_delivery=False)
-
SES_SNS_TRACKER_DEBUG_BACKEND = 'django.core.mail.backends.console.EmailBackend'
Set mail backend to use for the actual mail delivery in
DEBUG
mode (SESMailDelivery
objects will still be created). Default:None
-
Install development dependencies:
poetry install
-
Install the ruff extension for code linting & formatting in your IDE.
-
(Optional) Override settings in
example_proj/settings_local.py
&tests/settings_local.py
as required.