🎨 — Split mail in subject + content

This commit is contained in:
Luc Didry 2023-11-28 15:13:33 +01:00
parent 2ffea278dd
commit ec97d98231
No known key found for this signature in database
GPG key ID: EA868E12D0257E3C

View file

@ -15,20 +15,24 @@ def handle_alert(config: Config, result, task, severity):
logger.error("Alerting stub: %s", msg)
if config.general.mail is not None:
logger.debug('Notify of failure by mail')
logger.debug('Will send mail notification')
subject = f"[Argos] {urlparse(task.url).netloc}: status {severity}"
msg = f"""\
Subject: Argos {urlparse(task.url).netloc} status {severity}
URL: {task.url}
Check: {task.check}
Status: {severity}
Time: {result.submitted_at}
"""
notify_by_mail(msg, config.general.mail)
notify_by_mail(subject, msg, config.general.mail)
def notify_by_mail(msg: str, config: Mail) -> None:
def notify_by_mail(subject: str, msg: str, config: Mail) -> None:
mail = f"""\
Subject: {subject}
{msg}"""
if config.ssl:
logger.debug('Mail notification: SSL')
context = ssl.create_default_context()
@ -51,6 +55,6 @@ def notify_by_mail(msg: str, config: Mail) -> None:
for address in config.addresses:
logger.debug('Sending mail to %s', address)
logger.debug(msg)
smtp.sendmail(config.mailfrom, address, msg)
smtp.sendmail(config.mailfrom, address, mail)
return None