from __future__ import annotations import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText def send_schedule_mail(*, smtp_host: str, smtp_port: int, smtp_user: str, smtp_password: str, use_tls: bool, from_addr: str, to_addrs: list[str], subject: str, html_body: str) -> None: if not to_addrs: return msg = MIMEMultipart('alternative') msg['Subject'] = subject msg['From'] = from_addr msg['To'] = ', '.join(to_addrs) msg.attach(MIMEText(html_body, 'html', 'utf-8')) with smtplib.SMTP(smtp_host, smtp_port, timeout=20) as server: if use_tls: server.starttls() if smtp_user: server.login(smtp_user, smtp_password) server.sendmail(from_addr, to_addrs, msg.as_string()) def build_schedule_mail_html(*, schedule_name: str, run_no: str, status: str, total: int, success: int, failed: int) -> str: return ( "
" "| 排程 | {schedule_name} |
|---|---|
| 执行单号 | {run_no} |
| 状态 | {status} |
| 总数 | {total} |
| 成功 | {success} |
| 失败 | {failed} |