Django Celery Email

3.0.0 · active · verified Thu Apr 16

django-celery-email is an asynchronous email backend for Django that integrates with Celery to send emails in the background. This offloads email sending from the request-response cycle, improving web application responsiveness. The current version is 3.0.0, focusing on compatibility with modern Django and Python versions.

Common errors

Warnings

Install

Imports

Quickstart

To use django-celery-email, first ensure Celery and its broker (e.g., Redis) are installed and configured. Then, add 'django_celery_email' to `INSTALLED_APPS` and set `EMAIL_BACKEND` in your Django settings to `django_celery_email.backends.CeleryEmailBackend`. Emails sent via `django.core.mail.send_mail` or similar will then be processed asynchronously by Celery workers.

# settings.py

INSTALLED_APPS = [
    # ...
    'django_celery_email',
    # ...
]

# Configure Celery (e.g., using Redis as a broker)
CELERY_BROKER_URL = os.environ.get('CELERY_BROKER_URL', 'redis://localhost:6379/0')

# Point Django to use CeleryEmailBackend
EMAIL_BACKEND = 'django_celery_email.backends.CeleryEmailBackend'

# Optionally, specify the actual backend Celery should use to send emails
# Defaults to 'django.core.mail.backends.smtp.EmailBackend'
# CELERY_EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

# Optional: Configure Celery task options
CELERY_EMAIL_TASK_CONFIG = {
    'queue': 'celery_email',
    'rate_limit': '50/m',
}

# Example usage in an app (e.g., views.py)
from django.core.mail import send_mail

def my_view(request):
    send_mail(
        'Subject here',
        'Here is the message.',
        'from@example.com',
        ['to@example.com'],
        fail_silently=False,
    )
    return HttpResponse('Email scheduled!')

view raw JSON →