X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=tools%2Fnotify.py;h=bc0b4d84336d95f835f31b6dc1a8a6cb34b22914;hb=a974141892f10ff9f89908d878d1246f3983fe66;hp=4530255510787754beaaaa670aad191e4aa2fab8;hpb=63cf915b35fb1270e9cc99fcb42804d16bea1a7e;p=matthijs%2Fprojects%2Fxerxes.git diff --git a/tools/notify.py b/tools/notify.py index 4530255..bc0b4d8 100644 --- a/tools/notify.py +++ b/tools/notify.py @@ -1,7 +1,7 @@ from django.contrib.auth.models import User,Group from django.core.mail import EmailMessage from django.template import loader -from ee.tools.misc import make_iter +from xerxes.tools.misc import make_iter """ Notify someone about something. @@ -23,7 +23,7 @@ def notify(recipients, template, context = {}): context['addresses'] = addresses rendered = loader.render_to_string(template, context) - (headers, body) = rendered.split('\n\n', 2) + (headers, body) = rendered.split('\n\n', 1) # Turn the headers into a dict so EmailMessage can turn them into a # string again. Bit pointless, but it works. @@ -36,16 +36,23 @@ def notify(recipients, template, context = {}): from_email = None for header in headers.split('\n'): (field, value) = header.split(':') - headers_dict[field] = value if (field == 'From'): from_email = value + elif (field == 'Subject'): + subject = value + else: + # Don't put From and Subject in the dict, else they'll be + # present twice. + headers_dict[field] = value msg = EmailMessage( # Only setting the From address through headers won't set the # envelope address right. from_email = from_email, + subject = subject, body = body, to = addresses, headers = headers_dict ) msg.send() +# vim: set sts=4 sw=4 expandtab: