diff --git a/check.py b/check.py index 1ce98d3..55a5581 100755 --- a/check.py +++ b/check.py @@ -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()