From b74435f0fab4769a9a8334c47c4865356481199d Mon Sep 17 00:00:00 2001 From: Jonas Havelka Date: Tue, 25 May 2021 23:35:19 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Ododstavcov=C3=A1n=C3=AD=20mail=C5=AF?= =?UTF-8?q?=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- various/mail_prefixer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/various/mail_prefixer.py b/various/mail_prefixer.py index 76545bc3..7b09a81b 100644 --- a/various/mail_prefixer.py +++ b/various/mail_prefixer.py @@ -4,7 +4,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.core.mail.backends.console import EmailBackend as DjangoSMTPBackend from django.conf import settings class PrefixingMailBackend(DjangoSMTPBackend): @@ -14,7 +14,7 @@ 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.body = "Bylo by posláno na e-maily: " + str(message.recipients()) + "\n\n" + message.body message.to = settings.TESTOVACI_EMAILOVA_KONFERENCE message.cc = [] message.bcc = [] From 06c9dea6b5d611c6a08f43e24893d539cd5a64be Mon Sep 17 00:00:00 2001 From: Jonas Havelka Date: Tue, 25 May 2021 23:39:15 +0200 Subject: [PATCH 2/3] =?UTF-8?q?N=C3=A1vrat=20console=20->=20smtp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- various/mail_prefixer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/various/mail_prefixer.py b/various/mail_prefixer.py index 7b09a81b..94fe5fa9 100644 --- a/various/mail_prefixer.py +++ b/various/mail_prefixer.py @@ -4,7 +4,7 @@ Used to distinguish testing emails from production ones.""" # We try to monkeypatch django.core.mail.backends.smtp :-) -from django.core.mail.backends.console import EmailBackend as DjangoSMTPBackend +from django.core.mail.backends.smtp import EmailBackend as DjangoSMTPBackend from django.conf import settings class PrefixingMailBackend(DjangoSMTPBackend): From 3d61cf7907211dd4b9cbdaa8b23d41e30b5fdbe1 Mon Sep 17 00:00:00 2001 From: Jonas Havelka Date: Tue, 25 May 2021 23:49:39 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Vyjmout=20chybov=C3=A9=20hl=C3=A1=C5=A1ky.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- various/mail_prefixer.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/various/mail_prefixer.py b/various/mail_prefixer.py index 94fe5fa9..456b6be7 100644 --- a/various/mail_prefixer.py +++ b/various/mail_prefixer.py @@ -13,9 +13,11 @@ class PrefixingMailBackend(DjangoSMTPBackend): prefix = '[Mail z testwebu]' 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\n" + message.body - message.to = settings.TESTOVACI_EMAILOVA_KONFERENCE - message.cc = [] - message.bcc = [] + + if len(message.from_email) == 0 or message.from_email[0] != settings.SERVER_EMAIL: + message.subject = prefix + ' ' + message.subject + message.body = "Bylo by posláno na e-maily: " + str(message.recipients()) + "\n\n" + message.body + message.to = settings.TESTOVACI_EMAILOVA_KONFERENCE + message.cc = [] + message.bcc = [] return super().send_messages(messages)