Skip to main content

Email async notifications with celery.

Project description

Async notifications

Email notification with celery and administrative view for send email with delay e.g daily


  • Celery integration
  • Administrative view
  • Enqueued mail system and instantly send
  • Problems notification
  • User filter email
  • Template system with template context
  • Send to User, Group or external email
  • Django cms integration (djcms_async_notifications) and standalone.
  • Custom text area widget support
  • Allow send group mail list if it’s defined.


  1. Install from pip

    $ pip install async_notifications
  2. Add required apps in your settings **

  3. Add ajax_select urls in

    from django.conf.urls import url, include
    from ajax_select import urls as ajax_select_urls
    urlpatterns = [
        url(r'^ajax_select/', include(ajax_select_urls)),
  4. It’s really important set CELERY_MODULE pointing to your project celery file, because it’s needed for assing task to the current project, and configure some default celery options

    CELERY_MODULE = "demo.celery"
    CELERY_ACCEPT_CONTENT = ['pickle', 'json']
  5. Configure your email settings, e.g for development


# Copy celery app in your project folder from demo, and adjust the crontab execution

    # execute 12:30 pm
    'send_daily_emails': {
        'task': 'async_notifications.tasks.send_daily',
        'schedule': crontab(minute=30, hour=0),


Remember use demo/ to update your projectfolder/

  1. Run migrations

    $ python migrate

Runing the project

You need to run 3 subsystems for run this app so you need 3 xterm, for this explanation I will use the demo project

  1. Run smtp debug client

    $ python -m smtpd -n -c DebuggingServer localhost:1025
  2. Run celery, if you aren’t setup celery yet see celery documentation.

    $ celery -A demo worker -l info -B
  3. Run django

    $ python runserver


Report your context template

from async_notifications.register import update_template_context
context = [
    ('fieldname', 'Field description'),
    ('fieldname2', 'Field description'),
update_template_context("yourcode",  'your email subject', context )

This automátically create a Email template if not found.

Context is list of tuples with the fields available in the template context, this context is add in the same file that have send_email_from_template

Using with django templates

update_template_context("yourcode",  'your email subject', context, 'templatepath.html', as_template=True )

Send dict as context is now available, but remember that you can not repit keys in dict so use with precaution.

Send an email :)

send_email_from_template(code, recipient,

Params description:

  • recipient is a list of emails
  • code is the same code register in update_template_context
  • enqueued if False send the email immediately else enqueued to be sended when send email task run.
  • user user how send email
  • upfile attached file in email

Other optional options

Adding context dummy object

When you need to pass a default template message base on template, but you have not the template object and also you need to write the object with django template sintaxis you can use DummyContextObject that return always something like {{ myobj.attr1.objattr }}

from async_notifications.register import update_template_context, DummyContextObject
context = [
    ('myobj', 'Field description'),
message = render_to_string('some/template.html',
                           'myobj': DummyContextObject('myobj')
update_template_context("yourcode",  'your email subject', context, message=message )

Django cms integration

This configuration could help you to integrate with Django CMS.

include in your INSTALLED_APPS:


Configure how models and field async_notifications will use, ej. aldryn_people

ASYNC_NOTIFICATION_GROUP = 'aldryn_people.Group'
    'order_by': 'translations__name',
    'email': 'email',
    'group_lookup': 'translations__name',
    'display': 'name',
    'filter': ['translations__name__icontains']}

ASYNC_NOTIFICATION_USER = 'aldryn_people.Person'

    'order_by': 'translations__name',
    'display': 'name',
    'filter': [
    'group_lookup': 'groups__translations__name'}


Django auth is used by default


CONTACT_PLUS_SEND_METHOD = ‘async_notifications.djcms_async_notifications.contact_plus.send_email’ ASYNC_NOTIFICATION_CONTACT_PLUS_EMAIL = ‘email’


This requires special cmsplugin-contact-plus version, we send a PRs, but is not merged yet.

Default text area widget

For example using ckeditor widget

ASYNC_NOTIFICATION_TEXT_AREA_WIDGET = ‘ckeditor.widgets.CKEditorWidget’


See how to configure CKEditor .

Project details

Download files

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

Files for async_notifications, version 0.1.12
Filename, size File type Python version Upload date Hashes
Filename, size async_notifications-0.1.12.tar.gz (27.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page