From 77939a9c8bb4fed8766121dd73061c049e28fd7a Mon Sep 17 00:00:00 2001 From: Jonas Havelka Date: Tue, 25 May 2021 22:28:44 +0200 Subject: [PATCH] =?UTF-8?q?Zm=C4=9Bna=20p=C5=99=C3=ADjemc=C5=AF=20a=20zapn?= =?UTF-8?q?ut=C3=AD=20na=20testwebu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mamweb/settings_test.py | 5 +++++ various/mail_prefixer.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/mamweb/settings_test.py b/mamweb/settings_test.py index e8af9a88..c90d1e84 100644 --- a/mamweb/settings_test.py +++ b/mamweb/settings_test.py @@ -67,3 +67,8 @@ LOGGING['loggers']['']['handlers'] = ['console', 'mail_admins'] LOGGING['loggers']['django']['handlers'] = ['console', 'mail_admins'] LOGGING['handlers']['registration_logfile']['filename'] = '/home/mam-web/logs/test/registration.log' LOGGING['handlers']['registration_error_log']['filename'] = '/home/mam-web/logs/test/registration_errors.log' + +# Testování e-mailů +EMAIL_BACKEND = 'mamweb.various.mail_prefixer.PrefixingMailBackend' +# TODO Pouze na otestování testu… Zvolit konferu, případně může být i seznam +TESTOVACI_EMAILOVA_KONFERENCE = 'jonas.havelka@volny.cz' diff --git a/various/mail_prefixer.py b/various/mail_prefixer.py index b00c9d56..76545bc3 100644 --- a/various/mail_prefixer.py +++ b/various/mail_prefixer.py @@ -5,6 +5,7 @@ Used to distinguish testing emails from production ones.""" # We try to monkeypatch django.core.mail.backends.smtp :-) from django.core.mail.backends.smtp import EmailBackend as DjangoSMTPBackend +from django.conf import settings class PrefixingMailBackend(DjangoSMTPBackend): # method _send is not probably meant to be monkey_patched, so we patch send_messages instead. @@ -13,4 +14,8 @@ class PrefixingMailBackend(DjangoSMTPBackend): for message in messages: # We hope that this is a django.core.mail.message.EmailMessage message.subject = prefix + ' ' + message.subject + message.body = "Bylo by posláno na e-maily: " + str(message.recipients()) + "\n" + message.body + message.to = settings.TESTOVACI_EMAILOVA_KONFERENCE + message.cc = [] + message.bcc = [] return super().send_messages(messages)