#!/usr/bin/env python3
"""每日日报邮件发送脚本 - 外部团队版（无附件，含链接）
用法: python3 /data/news/scripts/send_daily_email_external.py
功能：自动获取当天日期（北京时间），发送含链接的邮件到外部团队
"""

import smtplib, ssl, sys
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import Header
from datetime import datetime, timezone, timedelta

# ── 配置 ──
SMTP_HOST = 'smtp.qq.com'
SMTP_PORT = 465
SMTP_USER = '954142763@qq.com'
SMTP_PASS = 'wdwrfvamnagabbif'

# 收件人（外部团队）
TO = ['sunwoo.hwang@hyundai.com']
CC = ['2304703@hmgc.com.cn', 'yjkim@innocean.com', 'gil@innocean.com', 'liuyanchen@innocean.com.cn']
ALL = TO + CC


def main():
    # 使用北京时间 (CST, UTC+8)
    bj_tz = timezone(timedelta(hours=8))
    dt = datetime.now(bj_tz)
    y, m, d = dt.year, dt.month, dt.day
    md_str = f'{m:02d}{d:02d}'  # 月日拼接

    msg = MIMEMultipart()
    msg['From'] = SMTP_USER
    msg['To'] = ', '.join(TO)
    msg['Cc'] = ', '.join(CC)
    msg['Subject'] = f'현대 브랜드 AI 일일 뉴스 리포트 - {y}년 {m}월 {d}일（现代品牌AI日报-{y}年{m}月{d}日）'

    body = (
        f'早上好：\n'
        f'今日品牌营销日报已生成，请点击链接查看\n'
        f'https://ai-dailyreport.cloud-top.com.cn/cn/?d={md_str}\n\n'
        f'좋은 아침입니다.\n'
        f'오늘의 브랜드 마케팅 데일리가 생성되었으니 링크를 클릭하여 확인해 주시기 바랍니다.\n'
        f'https://ai-dailyreport.cloud-top.com.cn/ko/?d={md_str}'
    )
    msg.attach(MIMEText(body, 'plain', 'utf-8'))

    context = ssl.create_default_context()
    with smtplib.SMTP_SSL(SMTP_HOST, SMTP_PORT, context=context, timeout=120) as server:
        server.login(SMTP_USER, SMTP_PASS)
        server.sendmail(SMTP_USER, ALL, msg.as_string())

    print(f'✅ {y}년 {m}월 {d}일 日报邮件已发送（外部团队，无附件含链接）')
    print(f'   收件人: {", ".join(ALL)}')


if __name__ == '__main__':
    main()

