File size: 1,218 Bytes
e5b86b0
 
651f96b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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}")