scripts/mails.py
author Madhusudan.C.S <madhusudancs@fossee.in>
Fri, 21 Jan 2011 19:47:43 +0530
changeset 509 288d1dfb81c0
child 511 50a5bdd313ac
permissions -rw-r--r--
Add a script for sending email to users.

"""Helper script to send emails to the users.
"""


__authors__ = [
  '"Madhusudan.C.S" <madhusudancs@gmail.com>',
  ]


from django.template import loader
from django.contrib.auth.models import User
from django.utils.translation import ugettext


def textbook_workshop_remainder(subject_template=None, body_template=None):
    """Sends a mail to each delegate about the template content specified.
    """

    users = User.objects.all()

    subject = loader.render_to_string(subject_template)

    for user in users:
        profile = user.getprofile()
        if profile:
            full_name = profile.name
        else:
            full_name = ''

        message = loader.render_to_string(
          body_template, dictionary={'name': full_name})

        user.email_user(subject=subject, message=message,
                        from_email='madhusudancs@fossee.in')