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())