Skip to main content

Django Queue Mailer

A reusable Django app for controlling queuing and sending of app emails. Key use case is to move sending of emails out of requests to speed-up request time and help to solve problems with sending email, handling deferring of email and logging of app email communication.

App started as a fork of Derek Stegelman’s Django Mail Queue and heavilly inspired by James Tauber’s django-mailer.

Any feedback, issues and suggestions are welcome. In that case please use Bitbucket’s issues.

Key features

  • Emails are queued and send as asynchronous task with help of Celery or Huey or as a crontab job scheduler.

  • With use of own backend easily integrated into existing app.

  • Easily configurable to use different mail backends as Django’s SMTP backend or Amazon SES using Sea Cucumber.

Installation

Install django_queue_mailer:

$ pip install django_queue_mailer

Add the following to your settings.py:

# Add django_queue_mailer to INSTALLED_APPS
INSTALLED_APPS = (
    ...
    "django_queue_mailer",
    ...
)

# Add django_queue_mailer's backend
EMAIL_BACKEND = "django_queue_mailer.backend.DbBackend"

# Setup email backend for sending queued emails
DJANGO_QUEUE_MAILER_EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"

# Or other backed as Sea Cucumber
DJANGO_QUEUE_MAILER_EMAIL_BACKEND = "seacucumber.backend.SESBackend"

You need to create the necessary tables. If you use south, just run migrations:

$ python manage.py migrate django_queue_mailer

If not, normal syncdb will do. For easier package upgrades using south for database migrations is strongly recommended.

$ python manage.py syncdb

Basic usage

Send emails and put them in queue with Django’s send_mail function:

from django.core.mail import send_mail

send_mail('Subject here', 'Here is the message.', 'from@example.com',
    ['to@example.com'], fail_silently=False)

Alternatively you can queue message with use of Queue model:

from django_queue_mailer.models import Queue

new_message = Queue()
new_message.subject = "Testing subject"
new_message.to_address = "nobody@example.com, noone@example.com"
new_message.bcc_address = "blindcopy@example.com"
new_message.from_address = "hello@example.com"
new_message.content = "Mail content"
new_message.html_content = "<h1>Mail Content</h1>"
new_message.app = "someapp"
new_message.save()

Queued messages can be send with use of Celery as asynchronous tasks. Example of Celery task, tasks.py in your app folder:

from django_queue_mailer.models import Queue

@celery.task
def send_mail():
    Queue.objects.send_queued()

Huey is a perfect lightweight Celery alternative. Example of using it’s multi-threaded tasks, periodical or event based (called from request when needed). Configure task in tasks.py:

from huey.djhuey import task, periodic_task, crontab
from django.core.management import call_command

@task()
@periodic_task(crontab(minute='*/2'))
def send_mail():
    call_command('send_queued_messages')

Simplest solution is to run crontab job, configure crontab using crontab -e:

*/2 * * * * path-to-virtualenv/bin/python path-to-app-folder/manage.py send_queued_messages

Further documentation

Will be added.

Metadata

Release files for django-queue-mailer 0.2.7

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-queue-mailer 0.2.7
File Size Uploaded Provenance Actions
django_queue_mailer-0.2.7.tar.gz 12.4 kB Without provenance Details for django_queue_mailer-0.2.7.tar.gz

Release files / django_queue_mailer-0.2.7.tar.gz

Download URL django_queue_mailer-0.2.7.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
113a0f016a3e6e5eb1a86643cdacf702119924e369f2cb835c669d67fe275146
BLAKE2b-256 checksum
How to use checksums
37a29d7aca4e2ba24d7d6f1797e527a402916a281524513c783e8359b0c35d3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.19.1 CPython/3.7.4

Security for django-queue-mailer 0.2.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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