customeragent-api / server /scripts /test_email.py
anasraza526's picture
Clean deploy to Hugging Face
ac90985
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())