There is a django-mailer application that I still did not know about, so the answer below describes my own approach.
The simplest case does not require much:
put this in your app/management/commands/send_email_alerts.py and then configure the cron job to run this command once a week using python manage.py send_email_alerts (all paths must be set in the environment, of course, for manage.py to choose your application 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 need to keep track of what you need to send an email to each user, and how often an additional code is required. Here is an example. It is possible that django-mailer can fill in the blanks.
Evgeny
source share