Add extensive logging to track email issues
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 25s

This commit is contained in:
vickytechkey 2026-08-23 10:05:27 +05:30
parent 5c09226868
commit 4cd45dc20b
2 changed files with 49 additions and 0 deletions

View file

@ -147,3 +147,45 @@ EMAIL_PORT = int(email_secret.get('smtp_port'))
EMAIL_USE_SSL = True
EMAIL_HOST_USER = email_secret.get('username')
EMAIL_HOST_PASSWORD = email_secret.get('password')
# Logging configuration
import os
LOGS_DIR = BASE_DIR / 'logs'
os.makedirs(LOGS_DIR, exist_ok=True)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
'style': '{',
},
},
'handlers': {
'app_file': {
'level': 'INFO',
'class': 'logging.FileHandler',
'filename': LOGS_DIR / 'app.log',
'formatter': 'verbose',
},
'error_file': {
'level': 'ERROR',
'class': 'logging.FileHandler',
'filename': LOGS_DIR / 'error.log',
'formatter': 'verbose',
},
},
'loggers': {
'django': {
'handlers': ['app_file', 'error_file'],
'level': 'INFO',
'propagate': True,
},
'mailer': {
'handlers': ['app_file', 'error_file'],
'level': 'INFO',
'propagate': True,
},
},
}

View file

@ -5,6 +5,9 @@ from django.template.loader import render_to_string
from django.utils.html import strip_tags
from django.conf import settings
from .models import EmailLog
import logging
logger = logging.getLogger(__name__)
def dashboard(request):
return render(request, 'mailer/dashboard.html')
@ -47,7 +50,10 @@ def send_test_email(request):
[recipient]
)
msg.attach_alternative(html_content, "text/html")
logger.info(f"Attempting to send '{template_name}' test email to {recipient} via {settings.EMAIL_HOST}")
msg.send(fail_silently=False)
logger.info(f"Successfully sent '{template_name}' email to {recipient}")
# Log success
EmailLog.objects.create(
@ -58,6 +64,7 @@ def send_test_email(request):
)
messages.success(request, f"Test email sent successfully to {recipient}!")
except Exception as e:
logger.error(f"Failed to send '{template_name}' email to {recipient}. Error: {str(e)}", exc_info=True)
# Log failure
EmailLog.objects.create(
recipient=recipient,