Make mail sending resilient: optional MAIL_FROM_NAME config and swallow send errors

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Edward Betts 2026-05-15 15:18:55 +00:00
parent 808efc3cb4
commit d75d617d11
2 changed files with 6 additions and 2 deletions

View file

@ -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()

View file

@ -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):