Skip to main content

Django email backend for celery.

Project description

A Django 1.2+ 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.

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',
    ...
}

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. See the Celery docs for more info.

len(results) will be the number of emails you attempted to send, and is in no way a reflection on the success or failure of their delivery.

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-1.0.0.tar.gz (6.5 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for django-celery-email-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e6c9d2b890b4f60f40151e3e36db0fe6dc4cbd9aecb3d49f3d49b8125667115a
MD5 b749ba9228197c75a6981913951d5980
BLAKE2b-256 cd697f43e26cf4c929f5f684f94d30aff3a1402556a1010c44364c1bda4c061f

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