| | import os |
| | import smtplib |
| | from email.mime.text import MIMEText |
| | import time |
| |
|
| | print("===== 🔍 環境變數偵測 =====") |
| | print("APP_PASSWORD =", os.getenv("APP_PASSWORD")) |
| | print("OPENAI_API_KEY =", os.getenv("OPENAI_API_KEY")) |
| | print("ALERT_EMAIL =", os.getenv("ALERT_EMAIL")) |
| | print("ALERT_PASS =", "(已設定)" if os.getenv("ALERT_PASS") else None) |
| |
|
| | ALERT_EMAIL = os.getenv("ALERT_EMAIL") |
| | ALERT_PASS = os.getenv("ALERT_PASS") |
| |
|
| | if not ALERT_EMAIL or not ALERT_PASS: |
| | print("⚠️ 無法測試寄信:請先設定 ALERT_EMAIL 與 ALERT_PASS 於 Variables。") |
| | exit(1) |
| |
|
| | |
| | |
| | |
| | msg = MIMEText(f"這是一封測試郵件。\n時間:{time.ctime()}", "plain", "utf-8") |
| | msg["Subject"] = "✅ 測試信件:Hugging Face SMTP 設定成功" |
| | msg["From"] = ALERT_EMAIL |
| | msg["To"] = ALERT_EMAIL |
| |
|
| | print("\n===== 📤 開始測試寄信 =====") |
| |
|
| | try: |
| | with smtplib.SMTP_SSL("smtp.gmail.com", 465) as server: |
| | server.login(ALERT_EMAIL, ALERT_PASS) |
| | server.sendmail(ALERT_EMAIL, ALERT_EMAIL, msg.as_string()) |
| | print(f"✅ 測試成功!郵件已寄出至 {ALERT_EMAIL}") |
| | except Exception as e: |
| | print(f"❌ 寄信失敗:{e}") |
| |
|