@@ -0,0 +1,2210 @@
+from django.conf import settings%0Afrom django.core.mail import send_mass_mail%0Afrom django.template.loader import render_to_string%0A%0A%0Adef simplify(value):%0A    %22%22%22%0A    Simplifies a string by removing leading and trailing whitespaces.%0A    Replaces also multiple whitespaces within the string with a single space.%0A    %22%22%22%0A    return ' '.join(value.strip().split())%0A%0A%0Adef render_mail_template(subject_template, body_template, context):%0A    %22%22%22%0A    Renders both the subject and body templates in the given context.%0A    Returns a tuple (subject, body) of the result.%0A    %22%22%22%0A    try:%0A        subject = simplify(render_to_string(subject_template, context))%0A        body = render_to_string(body_template, context)%0A    finally:%0A        pass%0A%0A    return subject, body%0A%0A%0Adef send_template_mail(subject_template, body_template, context, recipients):%0A    %22%22%22%0A    Renders an email subject and body using the given templates and context,%0A    then sends it to the given recipients list.%0A    %22%22%22%0A    subject, body = render_mail_template(subject_template, body_template, context)%0A%0A    # send resulting emails%0A    send_bulk_mail(subject, body, recipients)%0A%0A%0Adef send_bulk_mail(subject, body, recipients):%0A    %22%22%22%0A    Sends an email with the given subject and body to every recipient in the%0A    set/list of recipients. The emails are send one-by-one (so that no%0A    addresses are %22leaked%22, e.g. by putting all receivers in the %22TO: %22 field).%0A%0A    The sender email address is read from the settings.%0A    %22%22%22%0A%0A    message_tuples = %5B(subject, body, settings.DEFAULT_FROM_EMAIL, %5Br%5D)%0A                      for r in recipients%5D%0A%0A    send_mass_mail(message_tuples)%0A%0A%0Adef send_bulk_template_mail(subject_template, body_template, context, users):%0A    %22%22%22%0A    Similar to %60send_template_mail%60 this function renders the given templates%0A    into email subjects and bodies.%0A%0A    The resulting messages are collected and then sent at once using%0A    %60send_mass_mail%60.%0A    %22%22%22%0A    messages = %5B%5D%0A    for user in users:%0A        context%5B'user'%5D = user%0A        subject, body = render_mail_template(subject_template, body_template, context)%0A%0A        messages.append((subject, body, None, %5Buser.email%5D))%0A%0A    if messages:%0A        send_mass_mail(messages)%0A

Add mail utils