Skip to content

Fix SMTP connection handling, add logging and improve debugging - #88

Open
ThisIsMissEm wants to merge 4 commits into
dontcallmedom:mainfrom
ThisIsMissEm:fix/smtp-connection-and-logging
Open

ThisIsMissEm wants to merge 4 commits into
dontcallmedom:mainfrom
ThisIsMissEm:fix/smtp-connection-and-logging

Conversation

@ThisIsMissEm

@ThisIsMissEm ThisIsMissEm commented Oct 26, 2026 •

Copy link
Copy Markdown

SMTP:

  • Parse SMTP_SSL / SMTP_TLS as real booleans via envFlag(); previously the mere presence of a key (even "false") enabled it, which put SMTP_SSL on port 587 and failed with WRONG_VERSION_NUMBER
  • STARTTLS is now on by default (SMTP_TLS=false to disable) and never runs on top of SMTP_SSL; use a verifying default SSL context
  • Only log in when SMTP_USERNAME is set
  • Fix except ordering (SMTPConnectError was shadowed), catch OSError for refused/unreachable connections, coerce SMTP_TIMEOUT to a number
  • envFlag() rejects anything other than true/false so typos fail loudly

Logging:

  • Replace warn()/stderr with a module logger; configure in main
  • DEBUG=true enables debug logging, logs config with secrets masked, and logs digests instead of sending them
  • Log every outgoing HTTP request (URL, status, timing/cache hit)
  • Log non-200 GitHub API responses and repoList fetch failures that were previously swallowed

Debugging:

  • Add send-test-email.py for debugging connectivity issues without sending to the mailing list or involving github
  • index.py test-email ADDRESS: sends a one-off email through the same config and SMTP path as the digest, which makes it possible to debug mail delivery without involving GitHub or the mailing list.

Fixed:

  • PR titles in digests: since October 2025 the GitHub Events API sends a trimmed pull_request in PullRequestEvents (no title/html_url), so new PRs showed up as 643 (by JinDX). The digest now fetches the full PR when the title is missing, and falls back to the computed URL if that fails. The test fixtures had encoded the missing title, so I updated them as well.

Cleanup: resolve Ruff warnings (f-strings, open/OSError, specific exception types, sorted imports, mutable default argument).

Tested on the SWICG deployment (Debian 13, Python 3.13.5, Mailgun on 587 with STARTTLS): a test email arrived, and a DEBUG=true dry run of the weekly digest rendered correctly, including the PR titles.


This was based on the code I'd written to make the public-swicg github-notify-ml work, where I'd been getting all sorts of errors with TLS/SSL for SMTP with mailjet. The additional logging was added because I couldn't see anything about where it was at when it failed, and using the logging package allows loglines that include the date.

ThisIsMissEm and others added 4 commits October 26, 2026 04:00
SMTP:
- Parse SMTP_SSL / SMTP_TLS as real booleans via envFlag(); previously
  the mere presence of a key (even "false") enabled it, which put
  SMTP_SSL on port 587 and failed with WRONG_VERSION_NUMBER
- STARTTLS is now on by default (SMTP_TLS=false to disable) and never
  runs on top of SMTP_SSL; use a verifying default SSL context
- Only log in when SMTP_USERNAME is set
- Fix except ordering (SMTPConnectError was shadowed), catch OSError
  for refused/unreachable connections, coerce SMTP_TIMEOUT to a number
- envFlag() rejects anything other than true/false so typos fail loudly

Logging:
- Replace warn()/stderr with a module logger; configure in __main__
- DEBUG=true enables debug logging, logs config with secrets masked,
  and logs digests instead of sending them
- Log every outgoing HTTP request (URL, status, timing/cache hit)
- Log non-200 GitHub API responses and repoList fetch failures that
  were previously swallowed

Cleanup: resolve Ruff warnings (f-strings, open/OSError, specific
exception types, sorted imports, mutable default argument).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PFwWBnugzhAj6E1NAt5oFP
Since October 2025 the GitHub Events API sends a trimmed pull_request
object in PullRequestEvents, without title or html_url, so new PRs
appeared in digests as "940  (by aboba)". When the title is missing,
fetch the full pull request and merge it in; on failure, log a warning
and fall back to the computed html_url as before.

Update the digest test fixtures, which encoded the missing title.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PFwWBnugzhAj6E1NAt5oFP
@ThisIsMissEm ThisIsMissEm changed the title Fix SMTP connection handling and add logging Fix SMTP connection handling, add logging and improve debugging Oct 26, 2026
@ThisIsMissEm

Copy link
Copy Markdown
Author

@dontcallmedom if you want, I can split 97a4e97 out into a separate PR

@dontcallmedom

Copy link
Copy Markdown
Owner

A separate PR for the specific bug fix would be great (although the other changes are also definitely worth consideration)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants