import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

print('Sending test alert email...')
try:
    server = smtplib.SMTP_SSL('mail.ai4ksa.com', 465, timeout=30)
    server.login('ithelpdesk@ai4ksa.com', 'ithelpdesk@123')
    
    msg = MIMEMultipart()
    msg['From'] = 'SmartLife <ithelpdesk@ai4ksa.com>'
    msg['To'] = 'ashraffarid@gmail.com'
    msg['Subject'] = 'Test Alert - SmartLife'
    body = '<h2>Test Alert</h2><p>Temperature: 35C exceeded threshold 30C</p>'
    msg.attach(MIMEText(body, 'html', 'utf-8'))
    
    server.send_message(msg)
    server.quit()
    print('Alert sent successfully!')
except Exception as e:
    print(f'Error: {e}')
