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
+10
-5
@@ -20,11 +20,16 @@ CORS_ALLOWED_ORIGINS=https://holy.narl.io
|
|||||||
|
|
||||||
# --- SMTP Configuration (Required for Email Verification) ---
|
# --- SMTP Configuration (Required for Email Verification) ---
|
||||||
# For development, if EMAIL_HOST is empty, emails are printed to the console.
|
# For development, if EMAIL_HOST is empty, emails are printed to the console.
|
||||||
EMAIL_HOST=smtp.gmail.com
|
EMAIL_HOST=localhost
|
||||||
EMAIL_PORT=465
|
EMAIL_PORT=587
|
||||||
EMAIL_USE_SSL=true
|
# Use EMAIL_USE_TLS=true for STARTTLS (usually port 587)
|
||||||
EMAIL_HOST_USER="your-email@gmail.com"
|
EMAIL_USE_TLS=true
|
||||||
EMAIL_HOST_PASSWORD="your-app-specific-password"
|
# Use EMAIL_USE_SSL=true for implicit SSL (usually port 465)
|
||||||
|
EMAIL_USE_SSL=false
|
||||||
|
EMAIL_HOST_USER="your-email@example.com"
|
||||||
|
EMAIL_HOST_PASSWORD="your-password"
|
||||||
|
# Set to 'true' if using a self-signed certificate (e.g. local SMTP server)
|
||||||
|
EMAIL_SKIP_CERT_VERIFICATION=false
|
||||||
|
|
||||||
# --- Frontend Configuration ---
|
# --- Frontend Configuration ---
|
||||||
# The base URL of the backend API (MUST end with /api/)
|
# The base URL of the backend API (MUST end with /api/)
|
||||||
|
|||||||
@@ -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_USE_SSL = os.environ.get('EMAIL_USE_SSL', 'false').lower() == 'true'
|
||||||
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER')
|
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER')
|
||||||
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
|
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:
|
if EMAIL_HOST:
|
||||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
EMAIL_BACKEND = 'api.email_backend.InsecureEmailBackend'
|
||||||
else:
|
else:
|
||||||
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
|
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user