From d75d617d1115b33db81b25ca73ed2228ca9c90b9 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 15 May 2026 15:18:55 +0000 Subject: [PATCH] Make mail sending resilient: optional MAIL_FROM_NAME config and swallow send errors Co-Authored-By: Claude Sonnet 4.6 --- geocode/mail.py | 3 ++- geocode/wikidata.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/geocode/mail.py b/geocode/mail.py index f9586fa..136a373 100644 --- a/geocode/mail.py +++ b/geocode/mail.py @@ -15,7 +15,8 @@ def send_to_admin(subject: str, body: str) -> None: msg["Subject"] = subject msg["To"] = ", ".join(app.config["ADMINS"]) - msg["From"] = f'{app.config["MAIL_FROM_NAME"]} <{app.config["MAIL_FROM"]}>' + mail_from_name = app.config.get("MAIL_FROM_NAME", mail_from) + msg["From"] = f"{mail_from_name} <{mail_from}>" msg["Date"] = formatdate() msg["Message-ID"] = make_msgid() diff --git a/geocode/wikidata.py b/geocode/wikidata.py index 14ea217..e9d4828 100644 --- a/geocode/wikidata.py +++ b/geocode/wikidata.py @@ -21,7 +21,10 @@ def giveup(details: backoff.types.Details) -> None: last_exception = details["exception"] # type: ignore if last_exception and isinstance(last_exception, APIResponseError): body = f"Error making Wikidata API call\n\n{last_exception.response.text}" - mail.send_to_admin("Geocode error", body) + try: + mail.send_to_admin("Geocode error", body) + except Exception: + pass class QueryError(Exception):