From d27dd89a1fcd0ca158d7045f875c6365dc59a227 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sun, 11 Feb 2024 06:56:57 +0000 Subject: [PATCH] Read extra headers for mail from config --- check.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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()