Spaces:
Runtime error
Runtime error
| import asyncio | |
| import os | |
| import sys | |
| from dotenv import load_dotenv | |
| # Add server directory to path | |
| sys.path.append(os.path.join(os.getcwd(), "server")) | |
| load_dotenv() | |
| async def test_email_config(): | |
| print("π Diagnosing Email Configuration...") | |
| smtp_host = os.getenv("SMTP_HOST", "smtp.gmail.com") | |
| smtp_port = int(os.getenv("SMTP_PORT", "587")) | |
| smtp_user = os.getenv("SMTP_USER") | |
| smtp_password = os.getenv("SMTP_PASSWORD") | |
| print(f"π‘ SMTP Host: {smtp_host}:{smtp_port}") | |
| print(f"π€ SMTP User: {smtp_user}") | |
| print(f"π SMTP Password: {'****' if smtp_password and smtp_password != 'your-app-password' else 'MISSING/PLACEHOLDER'}") | |
| if not smtp_user or not smtp_password or smtp_password == "your-app-password": | |
| print("\nβ CRITICAL: SMTP credentials are not configured or are still using placeholders.") | |
| print("π‘ TIP: If using Gmail, you must generate an 'App Password' from your Google Account settings.") | |
| return | |
| try: | |
| import aiosmtplib | |
| from email.mime.text import MIMEText | |
| from email.mime.multipart import MIMEMultipart | |
| print("\nπ Attempting to send test email...") | |
| message = MIMEMultipart() | |
| message["From"] = smtp_user | |
| message["To"] = smtp_user # Send to yourself | |
| message["Subject"] = "π₯ Customer Agent - SMTP Test" | |
| body = "Congratulations! Your SMTP configuration is working correctly." | |
| message.attach(MIMEText(body, "plain")) | |
| await aiosmtplib.send( | |
| message, | |
| hostname=smtp_host, | |
| port=smtp_port, | |
| start_tls=True, | |
| username=smtp_user, | |
| password=smtp_password, | |
| timeout=10 | |
| ) | |
| print("\nβ SUCCESS: Test email sent successfully!") | |
| except Exception as e: | |
| print(f"\nβ FAILED: {str(e)}") | |
| if "AuthenticationFailed" in str(e): | |
| print("π‘ TIP: Verify your username and App Password. Ensure 'Less Secure Apps' is NOT what you're using for Gmail (it's deprecated).") | |
| elif "TimeoutError" in str(e): | |
| print("π‘ TIP: Check your firewall or internet connection. Port 587 might be blocked.") | |
| if __name__ == "__main__": | |
| asyncio.run(test_email_config()) | |