Monkeypatch mailového backendu
This commit is contained in:
parent
397650fc5f
commit
e5542372e9
1 changed files with 16 additions and 0 deletions
16
various/mail_prefixer.py
Normal file
16
various/mail_prefixer.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
"""A simple email backend, which only prepends all subjects with a string.
|
||||
|
||||
Used to distinguish testing emails from production ones."""
|
||||
|
||||
# We try to monkeypatch django.core.mail.backends.smtp :-)
|
||||
|
||||
from djago.core.mail.backends.smtp import EmailBackend as DjangoSMTPBackend
|
||||
|
||||
class PrefixingMailBackend(DjangoSMTPBackend):
|
||||
# method _send is not probably meant to be monkey_patched, so we patch send_messages instead.
|
||||
def send_messages(self, messages):
|
||||
prefix = '[Mail z testwebu]'
|
||||
for message in messages:
|
||||
# We hope that this is a django.core.mail.message.EmailMessage
|
||||
message.subject = prefix + ' ' + message.subject
|
||||
return super().send_messages(messages)
|
Loading…
Reference in a new issue