mirror of
https://github.com/narrrl/holy-flavor-rater.git
synced 2026-11-03 16:41:27 +01:00
added insecure email backend for self signed certs
This commit is contained in:
1 parent
01ae1a0449
commit
3097073f86
3 files changed
+30
-6
No files matched your search
@@ -0,0 +1,18 @@
|
||||
import ssl
|
||||
from django.core.mail.backends.smtp import EmailBackend
|
||||
from django.conf import settings
|
||||
|
||||
class InsecureEmailBackend(EmailBackend):
|
||||
"""
|
||||
SMTP email backend that allows skipping SSL certificate verification.
|
||||
Useful for local development or internal SMTP servers with self-signed certificates.
|
||||
Set EMAIL_SKIP_CERT_VERIFICATION = True in settings to use.
|
||||
"""
|
||||
@property
|
||||
def ssl_context(self):
|
||||
if getattr(settings, 'EMAIL_SKIP_CERT_VERIFICATION', False):
|
||||
context = ssl.create_default_context()
|
||||
context.check_hostname = False
|
||||
context.verify_mode = ssl.CERT_NONE
|
||||
return context
|
||||
return super().ssl_context
|
||||
@@ -205,9 +205,10 @@ EMAIL_USE_TLS = os.environ.get('EMAIL_USE_TLS', 'false').lower() == 'true'
|
||||
EMAIL_USE_SSL = os.environ.get('EMAIL_USE_SSL', 'false').lower() == 'true'
|
||||
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER')
|
||||
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
|
||||
EMAIL_SKIP_CERT_VERIFICATION = os.environ.get('EMAIL_SKIP_CERT_VERIFICATION', 'false').lower() == 'true'
|
||||
|
||||
if EMAIL_HOST:
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||
EMAIL_BACKEND = 'api.email_backend.InsecureEmailBackend'
|
||||
else:
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
|
||||
|
||||
|
||||
Reference in new issue
Block a user