From b9d89d74f71c043d5269c73e69e0f08b6cccaf4b Mon Sep 17 00:00:00 2001 From: Dmitriy Sintsov Date: Sun, 5 Mar 2023 12:07:35 +0300 Subject: [PATCH] [4.2.x] Fixed #34386 -- Made SMTP backend load default system root CA certificates by default. Regression in 2848e5d0ce5cf3c31fe87525536093b21d570f69. Backport of c914d6cff176ae6bfab2f33a84bcfd45208f1894 from main --- django/core/mail/backends/smtp.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/django/core/mail/backends/smtp.py b/django/core/mail/backends/smtp.py index 7ce29d27fd..c7ba06cde2 100644 --- a/django/core/mail/backends/smtp.py +++ b/django/core/mail/backends/smtp.py @@ -57,10 +57,12 @@ class EmailBackend(BaseEmailBackend): @cached_property def ssl_context(self): - ssl_context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLS_CLIENT) if self.ssl_certfile or self.ssl_keyfile: + ssl_context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLS_CLIENT) ssl_context.load_cert_chain(self.ssl_certfile, self.ssl_keyfile) - return ssl_context + return ssl_context + else: + return ssl.create_default_context() def open(self): """