Read extra headers for mail from config

This commit is contained in:
Edward Betts 2024-02-11 06:56:57 +00:00
parent 99e61f8fb7
commit d27dd89a1f

View file

@ -2,6 +2,8 @@
"""Check if conference websites are live."""
import configparser
import os
import re
import smtplib
import warnings
@ -9,7 +11,17 @@ from email.mime.text import MIMEText
from email.utils import formatdate, make_msgid
import requests
from urllib3.exceptions import InsecureRequestWarning
from urllib3.exceptions import InsecureRequestWarning # type: ignore
config_file_path = os.path.expanduser(
os.path.join(
os.getenv("XDG_CONFIG_HOME", "~/.config"), "conference-check", "config"
)
)
config = configparser.ConfigParser()
config.read(os.path.expanduser(config_file_path))
# Suppress only the single InsecureRequestWarning from urllib3
warnings.filterwarnings("ignore", category=InsecureRequestWarning)
@ -102,6 +114,10 @@ def send_mail(subject: str, body: str) -> None:
msg["Date"] = formatdate()
msg["Message-ID"] = make_msgid()
# extra mail headers from config
for header_name, value in config["mail_headers"].items():
msg[header_name] = value
s = smtplib.SMTP(SMTP_HOST)
s.sendmail(mail_from, [MAIL_TO_ADDRESS], msg.as_string())
s.quit()