Read extra headers for mail from config
This commit is contained in:
parent
99e61f8fb7
commit
d27dd89a1f
18
check.py
18
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()
|
||||
|
|
Loading…
Reference in a new issue