Skip to main content

An async Django email backend using celery

Project description

https://img.shields.io/travis/pmclanahan/django-celery-email/master.svg https://img.shields.io/pypi/v/django-celery-email.svg

A Django email backend that uses a Celery queue for out-of-band sending of the messages.

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.

Changelog

2.0.1 - 2018.18.27

  • Fix bug preventing sending text/* encoded mime attachments. Thanks Cesar Canassa.

2.0 - 2017.07.10

  • Support for Django 1.11 and Celery 4.0

  • Dropped support for Celery 2.x and 3.x

  • Dropped support for Python 3.3

1.1.5 - 2016.07.20

  • Support extra email attributes via CELERY_EMAIL_MESSAGE_EXTRA_ATTRIBUTES setting

  • Updated version requirements in README

1.1.4 - 2016.01.19

  • Support sending email with embedded images. Thanks Georg Zimmer.

  • Document CELERY_EMAIL_CHUNK_SIZE. Thanks Jonas Haag.

  • Add exception handling to email backend connection. Thanks Tom.

1.1.3 - 2015.11.06

  • Support setting celery.base from string. Thanks Matthew Jacobi.

  • Use six for py2/3 string compatibility. Thanks Matthew Jacobi.

  • Pass content_subtype back in for retries. Thanks Mark Joshua Tan.

  • Rework how tests work, add tox, rework travis-ci matrix.

  • Use six from django.utils.

  • Release a universal wheel.

1.1.2 - 2015.07.06

  • Fix for HTML-only emails. Thanks gnarvaja.

1.1.1 - 2015.03.20

  • Fix for backward compatibility of task kwarg handling - Thanks Jeremy Thurgood.

1.1.0 - 2015.03.06

  • New PyPI release rolling up 1.0.5 changes and some cleanup.

  • More backward compatability in task. Will still accept message objects and lists of message objects.

  • Thanks again to everyone who contributed to 1.0.5.

1.0.5 - 2014.08.24

  • Django 1.6 support, Travis CI testing, chunked sending & more - thanks Jonas Haag.

  • HTML email support - thanks Andres Riancho.

  • Support for JSON transit for Celery, sponsored by DigiACTive.

  • Drop support for Django 1.2.

1.0.4 - 2013.10.12

  • Add Django 1.5.2 and Python 3 support.

  • Thanks to Stefan Wehrmeyer for the contribution.

1.0.3 - 2012.03.06

  • Backend will now pass any kwargs with which it is initialized to the email sending backend.

  • Thanks to Fedor Tyurin for the contribution.

1.0.2 - 2012.02.21

  • Task and backend now accept kwargs that can be used in signal handlers.

  • Task now returns the result from the email sending backend.

  • Thanks to Yehonatan Daniv for these changes.

1.0.1 - 2011.10.06

  • Fixed a bug that resulted in tasks that were throwing errors reporting success.

  • If there is an exception thrown by the sending email backend, the result of the task will now be this exception.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-celery-email-2.0.1.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

django_celery_email-2.0.1-py2.py3-none-any.whl (8.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-celery-email-2.0.1.tar.gz.

File metadata

  • Download URL: django-celery-email-2.0.1.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.14

File hashes

Hashes for django-celery-email-2.0.1.tar.gz
Algorithm Hash digest
SHA256 1b2e0e31c6266007463befdc23934696fc93dcf320dfc85b8bb6b063cfe9558a
MD5 f80a74a731803d8b2d5988d08779c6ea
BLAKE2b-256 dd3ea803c67608f9c44e0011965289542b97bbb2b2a33a393872f773a30dbd45

See more details on using hashes here.

File details

Details for the file django_celery_email-2.0.1-py2.py3-none-any.whl.

File metadata

  • Download URL: django_celery_email-2.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/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/2.7.14

File hashes

Hashes for django_celery_email-2.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e5f9122c02ec58d3e49653475ad1b8612fd752681ce2f006d9c0792c57046283
MD5 b584d37d77b8bc30a32677d58606bbb2
BLAKE2b-256 04567a8427861153a8642761f113bf9e1d04a3b7d175c22864e47927720cf611

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page