An async Django email backend using celery (forked from django-celery-email)
Project description
A Django email backend that uses a Celery queue for out-of-band sending of the messages.
This is a fork of django_celery_email. As this package has gone unmaintained for some time, we have decided to maintain the package in order to maintain compatability with future Django versions, starting with Django 4.x and 5.x.
Using django-celery-email
To enable django-celery-email for your project you need to add djcelery_email to INSTALLED_APPS:
INSTALLED_APPS += ("djcelery_email",)
You must then set django-celery-email as your EMAIL_BACKEND:
EMAIL_BACKEND = 'djcelery_email.backends.CeleryEmailBackend'
By default django-celery-email will use Django’s builtin SMTP email backend for the actual sending of the mail. If you’d like to use another backend, you may set it in CELERY_EMAIL_BACKEND just like you would normally have set EMAIL_BACKEND before you were using Celery. In fact, the normal installation procedure will most likely be to get your email working using only Django, then change EMAIL_BACKEND to CELERY_EMAIL_BACKEND, and then add the new EMAIL_BACKEND setting from above.
Mass email are sent in chunks of size CELERY_EMAIL_CHUNK_SIZE (defaults to 10).
If you need to set any of the settings (attributes) you’d normally be able to set on a Celery Task class had you written it yourself, you may specify them in a dict in the CELERY_EMAIL_TASK_CONFIG setting:
CELERY_EMAIL_TASK_CONFIG = { 'queue' : 'email', 'rate_limit' : '50/m', # * CELERY_EMAIL_CHUNK_SIZE (default: 10) ... }
There are some default settings. Unless you specify otherwise, the equivalent of the following settings will apply:
CELERY_EMAIL_TASK_CONFIG = { 'name': 'djcelery_email_send', 'ignore_result': True, }
After this setup is complete, and you have a working Celery install, sending email will work exactly like it did before, except that the sending will be handled by your Celery workers:
from django.core import mail emails = ( ('Hey Man', "I'm The Dude! So that's what you call me.", 'dude@aol.com', ['mr@lebowski.com']), ('Dammit Walter', "Let's go bowlin'.", 'dude@aol.com', ['wsobchak@vfw.org']), ) results = mail.send_mass_mail(emails)
results will be a list of celery AsyncResult objects that you may ignore, or use to check the status of the email delivery task, or even wait for it to complete if want. You have to enable a result backend and set ignore_result to False in CELERY_EMAIL_TASK_CONFIG if you want to use these. You should also set CELERY_EMAIL_CHUNK_SIZE = 1 in settings if you are concerned about task status and results.
See the Celery docs for more info.
len(results) will be the number of emails you attempted to send divided by CELERY_EMAIL_CHUNK_SIZE, and is in no way a reflection on the success or failure of their delivery.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_celery_email_reboot-4.0.1.tar.gz
.
File metadata
- Download URL: django_celery_email_reboot-4.0.1.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7b04e7c3a1d6d22021dc5ca1bd3597e974549b9a39a328be5415b81929d3921 |
|
MD5 | 0f660456e9c9be1639bb47f6c9f1769b |
|
BLAKE2b-256 | a9d787d8a4ab2538834e23ba55a8629eeaded86db1f45273a1d1c3fc34c946d7 |
File details
Details for the file django_celery_email_reboot-4.0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: django_celery_email_reboot-4.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2a55a2d4f150ee4b11eabce29a0dbbfd401b0efa96b473c470718510d3ac237 |
|
MD5 | ef611af598ff80645884cca55d92d52e |
|
BLAKE2b-256 | 31221163a89f77c8b740aabaaf43f11a9ad219b4f365e5bac7969251259d1aee |