Django Anymail provides a unified interface for sending transactional emails and receiving webhooks across many Email Service Providers (ESPs) like SendGrid, Mailgun, Postmark, and more. It integrates seamlessly with Django's `EmailBackend` and `send_mail` functions, adding advanced features like ESP-specific options, transactional tracking, and inbound email signals. The library is actively maintained with frequent releases, currently at version 14.0, and supports various Django and Python versions.
pip install django-anymailVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure and use django-anymail to send emails via an ESP (Mailgun is used as an example). It shows both the standard `send_mail` function and the extended `AnymailMessage` for ESP-specific features like tags. Remember to replace placeholder API keys and recipient emails. For a real Django project, the `settings.configure` block is not needed, as settings would be in your project's `settings.py`.
Review your email content and templates for non-ASCII characters. Consult the Anymail documentation's 'International email' section (https://anymail.dev/en/stable/tips/international_email/) for guidance on handling specific character sets and ESP limitations.
Update your `esp_extra` usage for Amazon SES to pass a dictionary (instead of a string). For SparkPost, ensure `use_org_defaults=True` is included in your template parameters when `template_id` is set.
When configuring webhook URLs in `urls.py`, wrap `AnymailWebhooksView.as_view()` with `django.views.decorators.csrf.csrf_exempt`. Example: `path('anymail/webhooks/', csrf_exempt(AnymailWebhooksView.as_view()), name='anymail-webhooks')`.Ensure `ANYMAIL = { 'YOUR_ESP_API_KEY': '...' }` is correctly defined in `settings.py`, and the key name matches the exact environment variable/setting name required by your chosen ESP as per Anymail documentation.