import smtplib
from email.mime.text import MIMEText

sender = 'safecorner@163.com'
receiver = 'safecorner@163.com'
# Note: 163 SMTP requires authorization code, not login password
# The user needs to provide this
auth_code = 'NEED_AUTH_CODE'

subject = 'CRM Application Deployment - Database Connection Issue'
body = '''Dear User,

I am deploying the integrated_crm_app project and encountered a database connection issue:

PROBLEM:
- MariaDB is running (listening on 127.0.0.1:3306)
- Cannot connect with hermes/hermes123 (ERROR 1698: Access denied)
- This is likely a unix_socket authentication issue

PLEASE RUN ONE OF THESE COMMANDS:

Option 1 (recommended):
sudo mysql -u root -e "ALTER USER 'hermes'@'localhost' IDENTIFIED BY 'hermes123'; FLUSH PRIVILEGES;"

Option 2:
sudo mysql -u root -e "CREATE USER 'hermesai'@'localhost' IDENTIFIED BY 'hermesai123'; GRANT ALL PRIVILEGES ON *.* TO 'hermesai'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES;"

Or provide sudo password so I can fix it directly.

I will proceed with code review and build script fixes while waiting.

Thanks,
Hermes Agent
'''

msg = MIMEText(body, 'plain', 'utf-8')
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = receiver

try:
    server = smtplib.SMTP('smtp.163.com', 25)
    server.starttls()
    server.login(sender, auth_code)
    server.send_message(msg)
    server.quit()
    print('Email sent successfully')
except Exception as e:
    print(f'Email failed: {e}')
    print('Please manually send the above email to safecorner@163.com')
