Bin
2025-12-17 2e6c955be321cefd7e0c4a3031eab805e0a5a303
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import ssl
 
from django.core.mail.backends.smtp import EmailBackend
from django.utils.functional import cached_property
 
 
class NoVerificationEmailBackend(EmailBackend):
    """SMTP email backend that does not verify SSL certificates or hostname
    if no certfile or keyfile is provided. This is equivalent to the behavior
    of Django's smtp.EmailBackend prior to Django 4. If EmailBackend
    works for you, prefer that as it's more secure than this.
    """
 
    @cached_property
    def ssl_context(self):
        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
        else:
            ssl_context = ssl.create_default_context()
            ssl_context.check_hostname = False
            ssl_context.verify_mode = ssl.CERT_NONE
            return ssl_context