Source code for mindroot.coreplugins.email.test_email_service
#!/usr/bin/env python3"""Test script to verify email service functionality.Run this to test if email sending works with your configuration."""importasyncioimportosimportsyssys.path.append('/files/mindroot/src')frommindroot.coreplugins.email.modimportinit_email_provider,send_email
[docs]asyncdeftest_email_service():"""Test the email service with current environment configuration"""print("Testing email service...")# Check environment variablessmtp_email=os.getenv('SMTP_EMAIL')smtp_password=os.getenv('SMTP_PASSWORD')ifnotsmtp_emailornotsmtp_password:print("❌ Missing SMTP_EMAIL or SMTP_PASSWORD environment variables")print("Please set these environment variables:")print(" export SMTP_EMAIL='your-email@gmail.com'")print(" export SMTP_PASSWORD='your-app-password'")returnFalseprint(f"📧 Using SMTP email: {smtp_email}")# Initialize email providerprint("Initializing email provider...")success=awaitinit_email_provider()ifnotsuccess:print("❌ Failed to initialize email provider")returnFalseprint("✅ Email provider initialized successfully")# Test sending emailtest_email=input(f"Enter test email address (or press Enter to use {smtp_email}): ").strip()ifnottest_email:test_email=smtp_emailprint(f"Sending test email to {test_email}...")# Test HTML emailhtml_body=""" <html> <body> <h1>MindRoot Email Service Test</h1> <p>This is a test email from MindRoot.</p> <p><strong>HTML formatting works!</strong></p> <p>If you can see this styled content, HTML emails are working correctly.</p> </body> </html> """result=awaitsend_email(to=test_email,subject="MindRoot Email Service Test",body=html_body# HTML will be auto-detected)ifresult.get('success'):print("✅ Test email sent successfully!")print(f"Message ID: {result.get('message_id')}")returnTrueelse:print(f"❌ Failed to send test email: {result.get('error')}")returnFalse