Package: django-massmailer
django-massmailerdjango-massmaileris a standalone Django app that you can plug in your
website to send e-mails in bulk. It features:Ane-mail template engineto write your e-mail template, supporting both
plaintext and HTML, with a live preview:Aquery languageto select the subset of users you want to send e-mails
to, and preview the list of selected users:Abatch status reportthat shows how many e-mails have been sent, and is
able to track bounces.InstallationFirst, installdjango-massmailerand its Python dependencies:pip install django-massmailerThen, addmassmailerand its Django dependencies to your project'sINSTALLED_APPS:INSTALLED_APPS=(# ...'massmailer','crispy_forms','django_bootstrap_breadcrumbs','reversion',)Add the following URL pattern to yoururls.pyto put the mailing
dashboard in/mailing:urlpatterns=[# ...path('mailing',include('massmailer.urls')),]Then, execute the migrations to create the massmailer models:python3manage.pymigrateYou also need to have a working Celery setup with your website.
You can check out theofficial
tutorialto setup Celery in your Django website, or just look at how we do it in our demo
application:demoapp/__init__.pydemoapp/celery.pydemoapp/settings.pyHow to usePermissionsOnly staff users can see the mailing dashboard. By default, only superusers can
use anything in massmailer. There are three categories of permissions you
can grant to some staff users to allow them to make changes:mailing.{view,create,change,delete}_templateto view, create, change and
delete templates.mailing.{view,create,change,delete}_queryto view, create, change and
delete queries.⚠ These permissions give access to personal user data. ⚠mailing.{view,create,change,delete}_batchto view, send, change and
delete batches.⚠ These permissions give access to sending bulk e-mails. ⚠Becausedjango-massmailerintrinsically gives access to powerful features
(access to user data and sending e-mails in bulk) it is strongly recommended to
be as restrictive as possible when granting these permissions to prevent abuse
or spam.Query syntaxdjango-massmailerallows you to write queries in a domain-specific language
to select the users you want to reach. You can think of it as heavily
simplified SQL with a syntax that looks like filters in the Django ORM.Here is a short demonstration of the syntax:SomeModel[asname].field=42(.fieldcontains"string"or.fieldcontainsi"case insensitive")count(.related_field)>10aliassome_name=.some_fieldFilters are implicity joined by the and operator. If you are not querying on
the User model directly, you must create a user alias targeting a field
containing the related user.TemplatesTemplates use theJinja2 templating engineto
generate the contents of the e-mails. The model selected in your query will be
passed directly in the context of the template, as well as the different
aliases that were defined in the query.There are three templates you have to fill, one for the subject line, one for
the plaintext content, and optionally one for the HTML content. The HTML
template can also be generated directly from the plaintext e-mail.Example:Greetings,{{user.get_full_name().strip().title()}}!{%ifuser.is_staff%}With great power comes great responsibility.{%endif%}Template filtersIn addition to the Jinja2builtin
filters,django-massmailerprovides a few other convenience filters.The following filters are directly passed to theBabel functions of the same
nameusing the locale set in
template:format_date: formats the date according to a given pattern.format_time: formats the time according to a given pattern.format_datetime: formats the datetime according to a given pattern.Example:You have joined our website on{{user.date_joined|format_date}}.Contributingdjango-massmailerenforces various style constraints. You need to install
pre-commit hooks to make sure your commits respect them:pipinstall-rrequirements-dev.txt
pre-commitinstallLicencedjango-massmaileris distributed under the GPLv3 licence.Copyright (C) 2016 Alexandre MacabiesCopyright (C) 2016 Antoine PietriThis program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.You should have received a copy of the GNU General Public License
along with this program.  If not, seehttp://www.gnu.org/licenses/.