Skip to main content

Django Maja Newsletter

The problematic was :

How to couple a contact base to a mailing list and sending newsletters throught Django ?

Imagine that we have an application containing some kind of profiles or something like the django.contrib.auth and you want to send newsletters to them and tracking the activity.

This package is a fork of of emencia-django-newsletter with django 1.6 compatibility and other customizations

Features

More than a long speech, here the list of the main features :

  • Coupling capacities with another django model.

  • Variables can be used in the newsletter’s templates.

  • Mailing list managements (merging, importing…).

  • Import/Export of the contact in VCard 3.0.

  • Configurable SMTP servers with flow limit management.

  • Working groups.

  • Can send newsletter previews.

  • Subscriptions and unsubscriptions to mailing list.

  • Attachments in newsletters.

  • Unique urls for an user.

  • Tracking statistics.

Architecture

At the level of the application architecture, we can see 2 originalities who need to be explained.

Content types

The content types application is used to link any Contact model instance to another model instance. This allow you to create different kinds of contact linked to differents application, and retrieve the association at anytime.

This is particulary usefull with the templates variables if certain informations are located in the model instance linked.

Cronjob/Command

The maja_newsletter application will never send the newsletters registered in the site until you launch the send_newsletter command.

$ python manage.py send_newsletter

This command will launch the newsletters who need to be launched accordingly to the credits of the SMTP server of the newsletter. That’s mean that not all newsletters will be expedied at the end of the command because if you use a public SMTP server you can be banished temporarly if you reach the sending limit. To avoid banishment all the newsletters are not sended in the same time and immediately.

So it is recommanded to create a cronjob for launching this command every hours for example.

Installation

Dependencies

Make sure to install these packages prior to installation :

  • Django >= 1.2

  • html2text

  • BeautifulSoup

  • django-tagging

  • vobject

  • xlwt

  • xlrd

The package below is optionnal but handy for rendering a webpage in your newsletter.

  • lxml

Getting the code

You could retrieve the last sources from http://github.com/nephila/django-maja-newsletter and running the installation script

$ python setup.py install

or use pip

$ pip install -e git://github.com/nephila/django-maja-newsletter.git#egg=maja_newsletter

For the latest stable version use easy_install

$ easy_install django-maja-newsletter

Applications

Then register maja_newsletter, admin, contenttypes and tagging in the INSTALLED_APPS section of your project’s settings.

INSTALLED_APPS = (
  # Your favorites apps
  'django.contrib.contenttypes',
  'django.contrib.sites',
  'django.contrib.admin',
  'django.contrib.sessions',
  'tagging',
  'maja_newsletter',)

Urls

In your project urls.py adding this following line to include the newsletter’s urls for serving the newsletters in HTML.

url(r'^newsletters/', include('maja_newsletter.urls')),

Note this urlset is provided for convenient usage, but you can do something like that if you want to customize your urls :

url(r'^newsletters/', include('maja_newsletter.urls.newsletter')),
url(r'^mailing/', include('maja_newsletter.urls.mailing_list')),
url(r'^tracking/', include('maja_newsletter.urls.tracking')),
url(r'^statistics/', include('maja_newsletter.urls.statistics')),

Media Files

You have to make a symbolic link from maja_newsletter/media/edn/ directory to your media directory or make a copy named edn, but if want to change this value, define NEWSLETTER_MEDIA_URL in the settings.py as appropriate.

Don’t forget to serve this url.

Synchronization

Now you can run a syncdb for installing the models into your database.

Settings

You have to add in your settings the email address used to send the newsletter :

NEWSLETTER_DEFAULT_HEADER_SENDER = 'My NewsLetter <newsletter@myhost.com>'

DBMS considerations

It’s not recommended to use SQLite for production use. Because is limited to 999 variables into a SQL query, you can not create a Mailing List greater than this limitations in the Django’s admin modules. Prefer MySQL ou PgSQL.

HOWTO use TinyMCE for editing the newsletters

It can be usefull for the end user to have a WYSIWYG editor for the creation of the newsletter. The choice of the WYSIWYG editor is free and the described method can be applied for anything, but we will focus on TinyMCE because he has many features and a usefull plugin for loading templates within it.

First of all install the django-tinymce application into your project.

That’s done, enjoy !

HOWTO couple your profile application with maja_newsletter

If you wan to quickly import your contacts into a mailing list for example, you can write an admin’s action for your model.

We suppose that we have the fields email, first_name and last_name in a models name Profile.

In his AdminModel definition add this method and register it into the actions property.

class ProfileAdmin(admin.ModelAdmin):

    def make_mailing_list(self, request, queryset):
        from maja_newsletter.models import Contact
        from maja_newsletter.models import MailingList

        subscribers = []
        for profile in queryset:
            contact, created = Contact.objects.get_or_create(email=profile.mail,
                                                             defaults={'first_name': profile.first_name,
                                                                       'last_name': profile.last_name,
                                                                       'content_object': profile})
            subscribers.append(contact)
        new_mailing = MailingList(name='New mailing list',
                                  description='New mailing list created from admin/profile')
        new_mailing.save()
        new_mailing.subscribers.add(*subscribers)
        new_mailing.save()
        self.message_user(request, '%s succesfully created.' % new_mailing)
    make_mailing_list.short_description = 'Create a mailing list'

    actions = ['make_mailing_list']

This action will create or retrieve all the Contact instances needed for the mailing list creation.

After this you can send a newsletter to this mailing list.

Development

A Buildout script is provided to properly initialize the project for anybody who wants to contribute.

First of all, please use VirtualEnv to protect your system.

Follow these steps to start the development :

$ git clone git://github.com/nephila/django-maja-newsletter.git
$ virtualenv --no-site-packages maja_newsletter
$ cd maja_newsletter
$ source ./bin/activate
$ python bootstrap.py
$ ./bin/buildout

The buildout script will resolve all the dependancies needed to develop the application.

Once these operations are done, you are ready to develop on the project.

Run this command to launch the tests.

$ ./bin/test

Or you can also launch the demo.

$ ./bin/demo syncdb
$ ./bin/demo runserver

Pretty easy no ?

Database Representation

https://github.com/nephila/django-maja-newsletter/raw/master/docs/graph_model.png

Changelog

0.3

  • Use UTM Tags

  • Demo in the package

  • Improving importation

  • Premailer for HTML page.

  • New importation capabilities

  • Compatibility with django 1.3.1

  • Unique key variable for newsletter’s title

  • A lot of bug fixes

0.2

  • Plugin for django-cms

  • Multiple importation format

  • Compatibility with django 1.2

  • A lot of bug fixes

0.1dev (unreleased)

  • Initial release

Metadata

Release files for django-maja-newsletter 0.6.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-maja-newsletter 0.6.0
File Size Uploaded Provenance Actions
django-maja-newsletter-0.6.0.tar.gz 580.8 kB Without provenance Details for django-maja-newsletter-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-maja-newsletter 0.6.0
File Interpreter ABI Platform Actions
django_maja_newsletter-0.6.0-py2-none-any.whl Python 2 none any Details for django_maja_newsletter-0.6.0-py2-none-any.whl

Total release size: 1.1 MB

Release files / django-maja-newsletter-0.6.0.tar.gz

Download URL django-maja-newsletter-0.6.0.tar.gz
Size 580.8 kB
Tags Source
SHA-256 checksum
How to use checksums
93cac2edfbb517c4ac2646d0f4eccf694015133d4f08de3025f5b723f94c922e
BLAKE2b-256 checksum
How to use checksums
8462e21b32100538a3df582012d8d1e7bef2047ad37c28cf4f346d2f58dd11cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_maja_newsletter-0.6.0-py2-none-any.whl

Download URL django_maja_newsletter-0.6.0-py2-none-any.whl
Size 563.3 kB
Tags Python 2
SHA-256 checksum
How to use checksums
e9b90da272af67e0e2f81db73173e976ca085d05d20addd140d8d2ecaac700ed
BLAKE2b-256 checksum
How to use checksums
d18eb8f4bbf47c3b00c8a6b1aef0fca038d5e959299d11985ee2b6d25b1a5415
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-maja-newsletter 0.6.0

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