diff --git a/src/ddns_service/email.py b/src/ddns_service/email.py index 21d62d9..8b6dc9a 100644 --- a/src/ddns_service/email.py +++ b/src/ddns_service/email.py @@ -5,6 +5,7 @@ import smtplib from . import datetime_str from email.mime.text import MIMEText +from email.utils import formatdate from jinja2 import Environment, BaseLoader @@ -70,6 +71,7 @@ class EmailService: msg["Subject"] = subject msg["From"] = self.config["from_address"] msg["To"] = to + msg["Date"] = formatdate(localtime=True) smtp_host = self.config["smtp_host"] smtp_port = self.config["smtp_port"] diff --git a/src/ddns_service/server.py b/src/ddns_service/server.py index ecb0966..d4bcade 100644 --- a/src/ddns_service/server.py +++ b/src/ddns_service/server.py @@ -364,6 +364,10 @@ class DDNSRequestHandler(BaseHTTPRequestHandler): # Update database hostname.save() + notify_change_val = extract_param(params, endpoint["params"]["notify_change"]) + notify_change = notify_change_val.lower() not in ["0", "n", "no", "off"] \ + if notify_change_val else False + changed_addrs = "" if ipv4_changed: changed_addrs += f" ipv4={ipv4}" @@ -373,7 +377,7 @@ class DDNSRequestHandler(BaseHTTPRequestHandler): if not ipv4_changed and not ipv6_changed: logging.info( f"No change: client={client_ip} hostname={hostname.hostname} " - f"zone={hostname.zone}{changed_addrs}" + f"zone={hostname.zone}{changed_addrs} notify_change={notify_change}" ) return ( 200, "nochg", @@ -382,11 +386,10 @@ class DDNSRequestHandler(BaseHTTPRequestHandler): logging.info( f"Updated: client={client_ip} hostname={hostname.hostname} " - f"zone={hostname.zone}{changed_addrs}" + f"zone={hostname.zone}{changed_addrs} notify_change={notify_change}" ) - notify_change = extract_param(params, endpoint["params"]["notify_change"]) - if notify_change and notify_change.lower() not in ["0", "no", "off"]: + if notify_change: try: self.app.email_service.send_change_notification( hostname.user.email,