Skip to main content

Django Post Office is a simple mail queuing and logging app that allows you to keep track of email activities and send mails asynchronously in django.

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.

Dependencies

Installation

  • Install via pypi:

    pip install django-post_office
  • Add post_office to your INSTALLED_APPS in django’s settings.py:

    INSTALLED_APPS = (
        # other apps
        "post_office",
    )
  • Run syncdb:

    python manage.py syncdb
  • Set post_office.EmailBackend as your EMAIL_BACKEND in django’s settings.py:

    EMAIL_BACKEND = 'post_office.EmailBackend'

Usage

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 manage.py send_queued_mail. You can schedule this to run regularly via cron:

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

By default, post_office uses django’s SMTP EmailBackend. If you want to use a different one, 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:

INSTALLED_APPS = (
    # ...
    'django.contrib.admin',
    # ...
)

Management Commands

  • send_queued_mail will send queued emails. If there are any

    failures, they will be marked deferred and will not be attempted again by send_queued_mail.

  • cleanup_mail will delete mails 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 manage.py send_queued_mail >> $PROJECT/cron_mail.log 2>&1)
0 1 * * * (cd $PROJECT; python manage.py cleanup_mail --days=30 >> $PROJECT/cron_mail_cleanup.log 2>&1)

Lower Level Usage

post_office also comes with a send_mail command that is very similar to django’s, except that 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', 'from@example.com', ['to@example.com'],
          '<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, even if there’s another active process running send_queued_mail processing a thousand other messages:

from post_office import send_mail, PRIORITY
send_mail('subject', 'plaintext message', 'from@example.com', ['to@example.com'],
          '<p>HTML message</p>', priority=PRIORITY.now)

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

Metadata

Release files for django-post_office 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-post_office 0.1.0
File Size Uploaded
django-post_office-0.1.0.tar.gz 7.3 kB Details

Release files / django-post_office-0.1.0.tar.gz

Download URL django-post_office-0.1.0.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8d9e4704235a2b5191857d9e67aeefe422d052f8c1d0e7df5a5c02b24f5d7dbc
BLAKE2b-256 checksum
How to use checksums
6615033485bfa17ea2e233507a14b4758ec39ef2f2c4e5eada738ab4f46c4c3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

3.11.3

2 release files

3.11.2

2 release files

3.11.1

2 release files

3.10.0

2 release files

3.9.1

2 release files

3.9.0

2 release files

3.8.0

2 release files

3.7.1

2 release files

3.7.0

2 release files

3.6.3

2 release files

3.6.2

2 release files

3.6.1

2 release files

3.6.0

2 release files

3.5.3

1 release file

3.5.2

2 release files

3.5.1

1 release file

3.5.0

2 release files

3.4.1

1 release file

3.4.0

1 release file

3.3.1

2 release files

3.3.0

2 release files

3.2.1

1 release file

3.2.0

1 release file

3.1.0

2 release files

3.0.4

2 release files

3.0.3

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.0.8

2 release files

2.0.7

2 release files

2.0.6

2 release files

2.0.5

1 release file

2.0.4

1 release file

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.8.4

1 release file

0.8.3

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.2

1 release file

0.7.1

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

This release

0.1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page