# test_email.py
import smtplib
import os
from email.mime.text import MIMEText
from dotenv import load_dotenv

load_dotenv()

# Get credentials
username = os.getenv('MAIL_USERNAME')
password = os.getenv('MAIL_PASSWORD')  # App password

print(f"Testing with: {username}")

try:
    # Connect to server
    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.set_debuglevel(1)  # Shows full SMTP conversation
    server.starttls()
    
    # Login
    server.login(username, password)
    print("✓ LOGIN SUCCESSFUL")
    
    # Send test email
    msg = MIMEText("This is a test message from Flask app")
    msg['Subject'] = 'Test Email'
    msg['From'] = username
    msg['To'] = username
    
    server.send_message(msg)
    print("✓ EMAIL SENT SUCCESSFULLY")
    
    server.quit()
    
except Exception as e:
    print(f"✗ ERROR: {e}")