diff --git a/pinaxcon/monkey_patch.py b/pinaxcon/monkey_patch.py index 3cb61258ffee6656f381302ea968d7fae8678bac..a6b6d9cb4bada279db4e4982a068deff3bc00142 100644 --- a/pinaxcon/monkey_patch.py +++ b/pinaxcon/monkey_patch.py @@ -1,3 +1,8 @@ +from django.conf import settings +from django.core.mail import EmailMultiAlternatives +from functools import wraps + + class MonkeyPatchMiddleware(object): ''' Ensures that our monkey patching only gets called after it is safe to do so.''' @@ -7,6 +12,7 @@ class MonkeyPatchMiddleware(object): def do_monkey_patch(): patch_speaker_profile_form() + patch_accounts_to_send_bcc() # Remove this function from existence global do_monkey_patch @@ -15,7 +21,7 @@ def do_monkey_patch(): def patch_speaker_profile_form(): ''' Replaces textarea widgets with markdown editors. ''' - + import widgets from symposion.speakers.forms import SpeakerForm @@ -23,3 +29,30 @@ def patch_speaker_profile_form(): fields["biography"].widget = widgets.AceMarkdownEditor() fields["experience"].widget = widgets.AceMarkdownEditor() fields["accessibility"].widget = widgets.AceMarkdownEditor() + + +def patch_accounts_to_send_bcc(): + ''' Patches django-user-accounts' email functions to send a BCC e-mail to + the default BCC e-mail address. ''' + + from account import hooks + + # django-user-accounts always uses send_mail like: + # send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, to) + + if hasattr(settings, "ENVELOPE_BCC_LIST"): + bcc_email = settings.ENVELOPE_BCC_LIST + else: + bcc_email = None + + def send_mail(subject, message, from_email, to): + email = EmailMultiAlternatives( + subject, + message, + from_email, + to, + bcc=bcc_email, + ) + email.send() + + hooks.send_mail = send_mail