"""Send e-mail.""" import smtplib from email.message import EmailMessage from email.utils import formatdate, make_msgid import flask def send_mail(config: flask.config.Config, subject: str, body: str) -> None: """Send an e-mail.""" msg = EmailMessage() msg["Subject"] = subject msg["To"] = f"{config['NAME']} <{config['MAIL_TO']}>" msg["From"] = f"{config['NAME']} <{config['MAIL_FROM']}>" msg["Date"] = formatdate() msg["Message-ID"] = make_msgid() # Add extra mail headers for header, value in config["MAIL_HEADERS"]: msg[header] = value msg.set_content(body) s = smtplib.SMTP(config["SMTP_HOST"]) s.sendmail(config["MAIL_TO"], [config["MAIL_TO"]], msg.as_string()) s.quit()