#!/usr/bin/env python3
"""Test SMTP connection to Hetzner mail server."""
import smtplib
import sys
from email.mime.text import MIMEText

def test_smtp():
    """Test SMTP connection and authentication."""
    try:
        # Connect to mail server
        server = smtplib.SMTP('5.161.95.32', 587)
        server.ehlo()
        server.starttls()
        server.ehlo()
        
        # Authenticate
        server.login('marketing@commandsovereignty.com', 'CsMail2026!')
        
        # Send test email
        msg = MIMEText('This is a test email from Command Sovereignty.')
        msg['Subject'] = 'Command Sovereignty - SMTP Test'
        msg['From'] = 'marketing@commandsovereignty.com'
        msg['To'] = 'grepples15@gmail.com'
        
        server.sendmail(
            'marketing@commandsovereignty.com',
            ['grepples15@gmail.com'],
            msg.as_string()
        )
        
        print("✅ SMTP test successful! Check your inbox at grepples15@gmail.com")
        server.quit()
        return True
        
    except smtplib.SMTPAuthenticationError as e:
        print(f"❌ Authentication failed: {e}")
        return False
    except smtplib.SMTPException as e:
        print(f"❌ SMTP error: {e}")
        return False
    except Exception as e:
        print(f"❌ Connection error: {e}")
        return False

if __name__ == '__main__':
    success = test_smtp()
    sys.exit(0 if success else 1)
