Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django email digest

Is there an existing plug-in to produce daily or weekly digest emails in Django? (We want to combine many small notifications into one email, rather than bother people all the time.)

Django-mailer claims to support this, but I'm told it doesn't really.

like image 350
Jane Sales Avatar asked Nov 27 '09 11:11

Jane Sales


2 Answers

There is django-mailer app of which I was not aware till now, so the answer below details my own approach.

The simplest case won't require much:

put this into your app/management/commands/send_email_alerts.py, then set up a cron job to run this command once a week with python manage.py send_email_alerts (all paths must be set in the environment of course for manage.py to pick up your app settings)

from django.core.management.base import NoArgsCommand
from django.db import connection
from django.core.mail import EmailMessage

class Command(NoArgsCommand):
    def handle_noargs(self,**options):
        try:
            self.send_email_alerts()
        except Exception, e:
            print e
        finally:
            connection.close()

    def send_email_alerts(self):         
        for user in User.objects.all():
            text = 'Hi %s, here the news' % user.username
            subject = 'some subject'
            msg = EmailMessage(subject, text, settings.DEFAULT_FROM_EMAIL, [user.email])
            msg.send()

But if you will need to keep track of what to email each user and how often, some extra code will be needed. Here is a homegrown example. Maybe that's where django-mailer can fill in the gaps.

like image 52
Evgeny Avatar answered Sep 30 '22 18:09

Evgeny


I've just released the django-digested package to PyPI. It supports instant notifications, daily and weekly digests, and individual preferences for different groups of updates.

like image 25
Jerome Baum Avatar answered Sep 30 '22 18:09

Jerome Baum