skip to navigation
skip to content

django-post_office 0.1.4

A Django app that allows you to log email activities and send mail asynchronously.

Latest Version: 3.0.4

Django Post Office is a simple app that allows you to log email activities and asynchronously send emails in django. Supports HTML email.

The concept is similar to django-mailer and django-mailer-2. I maintained my own fork of django-mailer-2 here until I decided to make one from scratch because I wanted a cleaner code base.

post_office is implemented as a Django EmailBackend so you don’t need to change any of your code to start sending email asynchronously.



  • Install via pypi:

    pip install django-post_office
  • Add post_office to your INSTALLED_APPS in django’s

        # other apps
  • Run syncdb:

    python syncdb
  • Set post_office.EmailBackend as your EMAIL_BACKEND in django’s

    EMAIL_BACKEND = 'post_office.EmailBackend'


If you use post_office’s EmailBackend, it will automatically queue emails sent using django’s send_mail in the database.

To actually send them out, run python send_queued_mail. You can schedule this to run regularly via cron:

* * * * * (/usr/bin/python send_queued_mail >> send_mail.log 2>&1)

By default, post_office uses django’s SMTP EmailBackend. If you want to use a different backend, you can do so by changing POST_OFFICE_BACKEND.

For example if you want to use django-ses:

POST_OFFICE_BACKEND = 'django_ses.SESBackend'

You can view also queued emails along with their statuses if you have django’s admin interface enabled:

    # ...
    # ...

Management Commands

  • send_queued_mail - send queued emails, those that aren’t successfully sent they will be marked as failed.
  • cleanup_mail - delete all emails created before an X number of days (defaults to 90).

You may want to set these up via cron to run regularly:

* * * * * (cd $PROJECT; python send_queued_mail >> $PROJECT/cron_mail.log 2>&1)
0 1 * * * (cd $PROJECT; python cleanup_mail --days=30 >> $PROJECT/cron_mail_cleanup.log 2>&1)

Lower Level Usage

post_office also comes with a send_mail command similar to django’s. It accepts two extra arguments, html_message and priority (high, medium, low or now).

Here’s how to use it:

from post_office import send_mail, PRIORITY
send_mail('subject', 'plaintext message', '', [''],
          '<p>HTML message</p>', priority=PRIORITY.medium)

post_office is also task queue friendly. Passing now as priority into send_mail will deliver the email right away, regardless of how many emails you have in your queue:

from post_office import send_mail, PRIORITY
send_mail('subject', 'plaintext message', '', [''],
          '<p>HTML message</p>',

This is useful if you already use something like django-rq to send emails asynchronously and only need to store email activities and logs.

File Type Py Version Uploaded on Size
django-post_office-0.1.4.tar.gz (md5) Source 2012-09-03 9KB