• Stars
    star
    721
  • Rank 62,814 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 15 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

mail queuing and management for the Django web framework

Django Mailer

django-mailer

django-mailer is a reusable Django app for queuing the sending of email. It works by storing email in the database for later sending. The main reason for doing this is that for many apps, the database will be much more reliable and faster than other email sending backends which require 3rd party services e.g. SMTP or an HTTP API. By storing and sending later, we can return succeed immediately, and then attempt actual email sending in the background, with retries if needed.

An additional use case is that if you are storing the mail in the same database as your normal application, the database call can participate in any ongoing transaction - that is, if the database transaction is rolled back, the email sending will also be rolled back. (In some cases this behaviour might not be desirable, so be careful).

Keep in mind that file attachments are also temporarily stored in the database, which means if you are sending files larger than several hundred KB in size, you are likely to run into database limitations on how large your query can be. If this happens, you'll either need to fall back to using Django's default mail backend, or increase your database limits (a procedure that depends on which database you are using).

django-mailer was developed as part of the Pinax ecosystem but is just a Django app and can be used independently of other Pinax apps.

Requirements

  • Django >= 1.11
  • Databases: django-mailer supports all databases that Django supports, with the following notes:
    • SQLite: you may experience 'database is locked' errors if the send_mail command runs when anything else is attempting to put items on the queue. For this reason SQLite is not recommended for use with django-mailer.

Getting Started

Simple usage instructions:

In settings.py:

INSTALLED_APPS = [
    ...
    "mailer",
    ...
]

EMAIL_BACKEND = "mailer.backend.DbBackend"

Run database migrations to set up the needed database tables.

Then send email in the normal way, as per the Django email docs, and they will be added to the queue.

To actually send the messages on the queue, add this to a cron job file or equivalent:

*       * * * * (/path/to/your/python /path/to/your/manage.py send_mail >> ~/cron_mail.log 2>&1)
0,20,40 * * * * (/path/to/your/python /path/to/your/manage.py retry_deferred >> ~/cron_mail_deferred.log 2>&1)

To prevent from the database filling up with the message log, you should clean it up every once in a while.

To remove successful log entries older than a week, add this to a cron job file or equivalent:

0 0 * * * (/path/to/your/python /path/to/your/manage.py purge_mail_log 7 >> ~/cron_mail_purge.log 2>&1)

Use the -r failure option to remove only failed log entries instead, or -r all to remove them all.

Note that the send_mail cronjob can only run at a maximum frequency of once each minute. If a maximum delay of 60 seconds between creating an email and sending it is too much, an alternative is available.

Using ./manage.py runmailer a long running process is started that will check the database for new emails each MAILER_EMPTY_QUEUE_SLEEP (default: 30 seconds).

Documentation and support

See usage.rst in the docs for more advanced use cases. The Pinax documentation is available at http://pinaxproject.com/pinax/.

This is an Open Source project maintained by volunteers, and outside this documentation the maintainers do not offer other support. For cases where you have found a bug you can file a GitHub issue. In case of any questions we recommend you join the Pinax Slack team and ping the Pinax team there instead of creating an issue on GitHub. You may also be able to get help on other programming sites like Stack Overflow.

Contribute

See CONTRIBUTING.rst for information about contributing patches to django-mailer.

See this blog post including a video, or our How to Contribute section for an overview on how contributing to Pinax works. For concrete contribution ideas, please see our Ways to Contribute/What We Need Help With section.

We also highly recommend reading our Open Source and Self-Care blog post.

Code of Conduct

In order to foster a kind, inclusive, and harassment-free community, the Pinax Project has a code of conduct. We ask you to treat everyone as a smart human programmer that shares an interest in Python, Django, and Pinax with you.

Pinax Project Blog and Twitter

For updates and news regarding the Pinax Project, please follow us on Twitter at @pinaxproject and check out our blog.

More Repositories

1

pinax

a Django-based platform for rapidly developing websites
Python
2,624
star
2

django-user-accounts

User accounts for Django
Python
1,109
star
3

pinax-stripe-light

a payments Django app for Stripe
Python
677
star
4

pinax-blog

a blog app for Django
Python
461
star
5

pinax-badges

a badges app for Django
Python
316
star
6

symposion

a Django project for conference websites
Python
300
star
7

pinax-theme-bootstrap

A theme for Pinax based on Twitter's Bootstrap
HTML
269
star
8

pinax-referrals

a referrals app for Django
Python
208
star
9

pinax-messages

a Django app for allowing users of your site to send messages to each other
Python
197
star
10

django-forms-bootstrap

Bootstrap filter and templates for use with Django forms
Python
175
star
11

pinax-likes

a liking app for Django
Python
156
star
12

pinax-webanalytics

analytics and metrics integration for Django
Python
122
star
13

pinax-project-account

a starter project that incorporates account features from django-user-accounts
119
star
14

pinax-eventlog

An event logger
Python
108
star
15

pinax-invitations

a site invitation app for Django
Python
108
star
16

pinax-comments

a comments app for Django
Python
97
star
17

pinax-models

Provide Support for Logical Deletes on Models and in the Django Admin
Python
90
star
18

pinax-ratings

a ratings app for Django
Python
88
star
19

pinax-starter-projects

Pinax Starter Projects
Shell
79
star
20

django-flag

flagging of inapproriate/spam content
Python
73
star
21

django-waitinglist

DEPRECATED - please see https://github.com/pinax/pinax-waitinglist
Python
64
star
22

pinax-points

a points, positions and levels app for Django
Python
61
star
23

pinax-calendars

Django utilities for publishing events as a calendar
Python
61
star
24

pinax-documents

a document management app for Django
Python
59
star
25

pinax-teams

an app for Django sites that supports open, by invitation, and by application teams
Python
48
star
26

pinax-boxes

database-driven regions on webpages for Django
Python
48
star
27

pinax-starter-app

A starter app template for Pinax apps
Python
36
star
28

pinax-wiki

Easily add a wiki to your Django site
Python
32
star
29

pinax-project-symposion

a starter project demonstrating a minimal symposion instance
HTML
31
star
30

code.pinaxproject.com

the site behind code.pinaxproject.com
Python
29
star
31

pinax-forums

an extensible forums app for Django and Pinax
Python
27
star
32

pinax-project-zero

the foundation for other Pinax starter projects
25
star
33

pinax-waitinglist

a Django waiting list app
Python
25
star
34

pinax-testimonials

a testimonials app for Django
Python
24
star
35

pinax-project-teams

a starter project that has account management, profiles, teams and basic collaborative content.
18
star
36

pinax-images

an app for managing collections of images associated with a content object
Python
17
star
37

pinax-phone-confirmation

An app to provide phone confirmation via Twilio
Python
16
star
38

pinax-templates

semantic templates for pinax apps
HTML
15
star
39

pinax-project-socialauth

a starter project that supports social authentication
CSS
15
star
40

pinax-api

RESTful API adhering to the JSON:API specification
Python
13
star
41

pinax-submissions

an app for proposing and reviewing submissions
Python
12
star
42

pinax-project-blog

a blog starter project
10
star
43

pinax-project-forums

an out-of-the-box Pinax starter project implementing forums
HTML
10
star
44

pinax-images-panel

a React component for uploading and managing images with the pinax-images Django reusable app
JavaScript
9
star
45

pinax-cohorts

Create cohorts to invite to join your private beta site. Depends on pinax-waitinglist.
Python
9
star
46

pinax-pages

A light weight CMS born out of Symposion
Python
8
star
47

pinax-project-lms

A starter project to bring together components of the Pinax Learning Management System
CSS
7
star
48

pinax-cli

a tool for easily instantiating Pinax starter projects (django templates)
Python
7
star
49

django-site-access

an app to provide utilities via middleware to control access to your django site
Python
7
star
50

cloudspotting

a starter project allowing you to create collections of cloud images, view other peopleโ€™s collections, โ€œlikeโ€ a collection, etc.
CSS
7
star
51

pinax-calendars-demo

a demo project for pinax-calendars
Python
7
star
52

pinax-lms-activities

framework and base learning activities for Pinax LMS
Python
7
star
53

atom-format

Python
6
star
54

PinaxCon

PinaxCon is a project that demonstrates how Symposion can be hooked up for a conference site
HTML
6
star
55

pinax-events

a simple app for publishing events on your site
Python
5
star
56

pinax-news

a simple app for publishing links to news articles on your site
Python
5
star
57

pinax-utils

an app for Pinax utilities
Python
5
star
58

blog.pinaxproject.com

Python
5
star
59

pinax-types

Python
4
star
60

cloudspotting2

Pinax demo application showing many Pinax apps
CSS
4
star
61

pinax-project-static

3
star
62

pinax-cart

Python
3
star
63

pinax-identity

OpenID Connect with pinax-api helpers
Python
3
star
64

pinax-theme-classic

the original Pinax theme
HTML
3
star
65

pinax_theme_tester

a project based on the zero starter project used to test and build the pinax theme
Python
3
star
66

screencasts

2
star
67

pinax-project-wiki

a demo starter project for a single wiki site, featuring integration of pinax-wiki
2
star
68

lms-activities-demo

a Django site for demoing Pinax LMS Activities
Python
1
star
69

dashboard.pinaxproject.com

a collection of metrics and information about how the Pinax Project is going
Python
1
star
70

.github

Pinax Default Community Health Files
1
star
71

mytweets

a demo of pinax-types periods
Python
1
star
72

pinax-theme-pinaxproject

a Pinax theme for pinaxproject.com website
HTML
1
star
73

patch-game

guess the Pinax patch
CSS
1
star