#!/usr/bin/python3.12
"""每日日报邮件发送脚本 - 发给 lishujing@innocean.com.cn（无附件，含链接）
用法: python3 /data/news/scripts/send_daily_email_lishujing.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 = ['lishujing@innocean.com.cn']
ALL = TO


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['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}일 日报邮件已发送 -> lishujing@innocean.com.cn（无附件含链接）')


if __name__ == '__main__':
    main()

