20 lines
638 B
Python
20 lines
638 B
Python
import smtplib
|
|
from email.message import EmailMessage
|
|
from typing import Dict
|
|
|
|
def send_email(cfg: Dict[str, str], subject: str, body: str) -> None:
|
|
"""
|
|
Отправляет письмо через SMTP по настройкам из cfg.
|
|
Ожидает ключи: host, port, username, password, from, to.
|
|
"""
|
|
msg = EmailMessage()
|
|
msg['Subject'] = subject
|
|
msg['From'] = cfg['from']
|
|
msg['To'] = cfg['to']
|
|
msg.set_content(body)
|
|
|
|
with smtplib.SMTP(cfg['host'], cfg['port']) as smtp:
|
|
smtp.starttls()
|
|
smtp.login(cfg['username'], cfg['password'])
|
|
smtp.send_message(msg)
|