Files
ewoooc/tests/test_email_content.py
ogt 1b4f3a7bbe
Some checks failed
CD Pipeline / deploy (push) Failing after 59s
feat: EwoooC 初始化 — 完整專案推版至 Gitea
- 建立 Gitea Actions CD pipeline (.gitea/workflows/cd.yaml)
- 部署模式: rsync Python 檔案至 188 → docker restart (volume mount)
- Dockerfile/requirements 變動時自動重建 Docker image
- 部署通知: Telegram (開始/成功/失敗)
- 健康檢查: https://mo.wooo.work/health (最多 5 次重試)
- 同步最新 CLAUDE.md / ADR-008 / memory (2026-04-19)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 01:21:13 +08:00

89 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
測試郵件內容顯示
"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from services.vendor_email_service import VendorEmailService
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def test_email_content():
"""測試郵件 HTML 和純文字內容"""
print("=" * 80)
print("測試郵件內容生成")
print("=" * 80)
service = VendorEmailService()
# 測試 HTML 生成
html = service._generate_grouped_email_html(
vendor_name='測試廠商',
vendor_code='TEST001',
items=[]
)
print("\n📧 HTML 郵件內容:")
print("-" * 80)
print(html)
print("-" * 80)
print(f"HTML 長度: {len(html)} 字元")
# 測試 MIME 郵件結構
print("\n📨 MIME 郵件結構測試:")
print("-" * 80)
msg = MIMEMultipart('alternative')
msg['From'] = 'test@example.com'
msg['To'] = 'recipient@example.com'
msg['Subject'] = 'PChome_缺貨通知_TEST001 測試廠商'
# 純文字版本
text_body = """Dear 供應商:
以下商品請補貨上架,並回覆補貨數量及日期,有任何問題歡迎提出討論,謝謝!
詳細商品清單請參考附件 Excel 檔案。
此致
PChome 採購部"""
text_part = MIMEText(text_body, 'plain', 'utf-8')
msg.attach(text_part)
# HTML 版本
html_part = MIMEText(html, 'html', 'utf-8')
msg.attach(html_part)
print("✅ MIME 郵件結構已建立")
print(f" Parts: {len(msg.get_payload())}")
print(f" Part 1: {msg.get_payload()[0].get_content_type()}")
print(f" Part 2: {msg.get_payload()[1].get_content_type()}")
# 顯示完整郵件
print("\n📬 完整郵件內容 (前 1000 字元):")
print("-" * 80)
email_content = msg.as_string()
print(email_content[:1000])
print("\n... (省略)")
print("-" * 80)
print(f"完整郵件長度: {len(email_content)} 字元")
print("\n" + "=" * 80)
print("✅ 郵件內容測試完成")
print("=" * 80)
print("\n💡 建議:")
print(" 1. 如果收到郵件但看不到內容,請檢查郵件客戶端的 HTML 顯示設定")
print(" 2. 確認郵件沒有被分類到垃圾郵件")
print(" 3. 嘗試用不同的郵件客戶端開啟Gmail 網頁版、Outlook 等)")
print(" 4. 檢查是否有郵件過濾規則影響顯示")
if __name__ == '__main__':
test_email_content()