Package: django-mailer-ulamlabs
First, add “mailer” to yourINSTALLED_APPSin your settings.py.
Run./manage.py migrateto install models.Using EMAIL_BACKENDThis is the preferred and easiest way to use django-mailer.To automatically switch all your mail to use django-mailer, first set
EMAIL_BACKEND:EMAIL_BACKEND = "mailer.backend.DbBackend"If you were previously using a non-default EMAIL_BACKEND, you need to configure
the MAILER_EMAIL_BACKEND setting, so that django-mailer knows how to actually send
the mail:MAILER_EMAIL_BACKEND = "your.actual.EmailBackend"Now, just use the normalDjango mail functionsfor sending email. These
functions will store mail on a queue in the database, which must be sent as
below.Explicitly putting mail on the queueIf you don’t want to send all email through django-mailer, you can send mail
usingmailer.send_mail, which has the same signature as Django’ssend_mailfunction.You can also do the following:# favour django-mailer but fall back to django.core.mail
from django.conf import settings

if "mailer" in settings.INSTALLED_APPS:
    from mailer import send_mail
else:
    from django.core.mail import send_mailand then just call send_mail like you normally would in Django:send_mail(subject, message_body, settings.DEFAULT_FROM_EMAIL, recipients)There is also a convenience functionmailer.send_html_mailfor creating HTML
(this function isnotin Django):send_html_mail(subject, message_plaintext, message_html, settings.DEFAULT_FROM_EMAIL, recipients)Additionally you can send all the admins as specified in theADMINsetting by calling:mail_admins(subject, message_body)or all managers as defined in theMANAGERSsetting by calling:mail_managers(subject, message_body)Clear queue with command extensionsWith mailer in your INSTALLED_APPS, there will be three new manage.py commands
you can run:send_mailwill clear the current message queue. If there are any
failures, they will be marked deferred and will not be attempted again bysend_mail.retry_deferredwill move any deferred mail back into the normal queue
(so it will be attempted again on the nextsend_mail).purge_mail_logwill remove old successful message logs from the database, to prevent it from filling up your databaseYou may want to set these up via cron to run regularly:*       * * * * (/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)
0 0 * * * (/path/to/your/python /path/to/your/manage.py purge_mail_log 7 >> ~/cron_mail_purge.log 2>&1)For use in Pinax, for example, that might look like:* * * * * (cd $PINAX; /usr/local/bin/python2.5 manage.py send_mail >> $PINAX/cron_mail.log 2>&1)
0,20,40 * * * * (cd $PINAX; /usr/local/bin/python2.5 manage.py retry_deferred >> $PINAX/cron_mail_deferred.log 2>&1)
0 0 * * * (cd $PINAX; /usr/local/bin/python2.5 manage.py purge_mail_log 7 >> $PINAX/cron_mail_purge.log 2>&1)This attempts to send mail every minute with a retry on failure every 20
minutes, and purges the mail log for entries older than 7 days.manage.py send_mailuses a lock file in case clearing the queue takes
longer than the interval between callingmanage.py send_mail.Note that if your project lives inside a virtualenv, you also have to execute
this command from the virtualenv. The same, naturally, applies also if you’re
executing it with cron. ThePinax documentationexplains that in more
details.Controlling the delivery processIf you wish to have a finer control over the delivery process, which defaults
to deliver everything in the queue, you can use the following 3 variables
(default values shown):MAILER_EMAIL_MAX_BATCH = None  # integer or None
MAILER_EMAIL_MAX_DEFERRED = None  # integer or None
MAILER_EMAIL_THROTTLE = 0  # passed to time.sleep()These control how many emails are sent successfully before stopping the
current runMAILER_EMAIL_MAX_BATCH, after how many failed/deferred emails
should it stopMAILER_EMAIL_MAX_DEFERREDand how much time to wait between
each emailMAILER_EMAIL_THROTTLE.Unprocessed emails will be evaluated in the following delivery iterations.Other settingsIf you need to be able to control where django-mailer puts its lock file (used
to ensure mail is not sent twice), you can setMAILER_LOCK_PATHto a full
absolute path to the file to be used as a lock. The extension “.lock” will be
added. The process runningsend_mailneeds to have permissions to create and
delete this file, and others in the same directory. With the default value ofNonedjango-mailer will use a path in current working directory.
Change log
==========Unreleased1.2.2Django 1.10 support.Fixed reprs for Message and MessageLog.1.2.1More helpful admin for Message and MessageLogHandle exceptions from really old Django versions1.2.0Save theMessage-IDheader onMessageexplicitly to enable finding
emails using this identifier.This includes a database schema migration.1.1.0Deprecated callingsend_mailandsend_html_mailusingprioritykwargs"high","medium", and"low". Instead you should usePRIORITY_HIGH,PRIORITY_MEDIUMandPRIORITY_LOWfrommailer.models.Fixed bug with migrations for Django 1.7, which wanted to create a migration
to ‘fix’ the EmailField length back down to 75 instead of 254.1.0.1Included migrations - for both South and Django 1.7 native migrations.Note:If you use South, you will need at least South 1.0You will need to use ‘–fake’ or ‘–fake-initial’ on existing installations.These migrations were supposed to be in 1.0.0 but were omitted due to a
packaging error.1.0.0Throttling of email sendingDjango 1.8 supportAdmin tweaks and improvementsVarious other fixes, especially from Renato Alves <alves.rjc@gmail.com> - thank you!0.1.0First PyPI version