Download email_test.py from MichaelChou0806/LINE_audio_transcript: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/spaces/MichaelChou0806/LINE_audio_transcript/resolve/main/email_test.py
- Command line
-
hf download hf://spaces/MichaelChou0806/LINE_audio_transcript/email_test.py
-
curl -L -o email_test.py https://huggingface.co/spaces/MichaelChou0806/LINE_audio_transcript/resolve/main/email_test.py
1.22 kB
| 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}") | |