quantum-ai-v3/authentication/management/commands/test_email.py
Claude 498de2219e Add email debugging and better error handling
- Add debug_railway_email.py script for Railway email configuration testing
- Add management command test_email for Railway email testing
- Improve error handling and logging in forgot password view
- Add detailed email configuration debug information

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-16 13:17:15 +05:30

39 lines
1.5 KiB
Python

from django.core.management.base import BaseCommand
from django.core.mail import send_mail
from django.conf import settings
from authentication.models import User
class Command(BaseCommand):
help = 'Test email configuration on Railway'
def add_arguments(self, parser):
parser.add_argument('--email', type=str, help='Email address to send test to')
def handle(self, *args, **options):
self.stdout.write("🔍 Testing email configuration...")
# Check settings
self.stdout.write(f"EMAIL_BACKEND: {settings.EMAIL_BACKEND}")
self.stdout.write(f"EMAIL_HOST: {settings.EMAIL_HOST}")
self.stdout.write(f"EMAIL_HOST_USER: {settings.EMAIL_HOST_USER}")
self.stdout.write(f"DEFAULT_FROM_EMAIL: {settings.DEFAULT_FROM_EMAIL}")
# Get email to send to
email = options.get('email') or settings.EMAIL_HOST_USER
self.stdout.write(f"Sending test email to: {email}")
try:
send_mail(
'Railway Email Test',
'This is a test email from Railway deployment to verify email functionality.',
settings.DEFAULT_FROM_EMAIL,
[email],
fail_silently=False,
)
self.stdout.write(
self.style.SUCCESS(f'✅ Email sent successfully to {email}!')
)
except Exception as e:
self.stdout.write(
self.style.ERROR(f'❌ Failed to send email: {str(e)}')
)