Skip to content

feat(common): add SMTP test-email endpoint to sanity checks - #153

Draft
geourjoa wants to merge 2 commits into
feat-4/admin-sanity-checks-endpointfrom
feat-5/smtp-test-button
Draft

feat(common): add SMTP test-email endpoint to sanity checks#153
geourjoa wants to merge 2 commits into
feat-4/admin-sanity-checks-endpointfrom
feat-5/smtp-test-button

Conversation

@geourjoa

@geourjoa geourjoa commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

WIP

Stacked on #151 (feat-4) — merge/rebase after that lands.

  • New POST /api/v1/management/common/sanity-checks/test-email/, gated by IsSuperuser, short-circuits with 400 if smtp_configured() is false rather than attempting a doomed send.
  • Recipient is a validated request parameter — no ADMINS/MANAGERS/DEFAULT_FROM_EMAIL exists in settings today, so there's no fixed "send test emails here" address to default to. Worth deciding whether to add one instead long-term.
  • send_mail failures are caught narrowly (SMTPException, OSError), not via a bare except Exception, and return 502.

Test plan

  • ruff check / ruff format / mypy clean
  • pytest apps/common — 71 passed; email is always mocked, nothing real is ever sent in tests

No new dependencies.

WIP frontend companion PR

Adds POST /api/v1/management/common/sanity-checks/test-email/, a
superuser-gated sibling to the sanity-checks GET endpoint, letting an
admin verify SMTP delivery actually works end-to-end rather than just
inspecting config.

The project has no ADMINS/MANAGERS/DEFAULT_FROM_EMAIL pointing at a
real inbox, so the recipient is supplied by the caller and validated
as an email address. The endpoint reuses smtp_configured() to
short-circuit with 400 before attempting delivery via Django's
unconfigured localhost default, and the new send_test_email() service
function only swallows smtplib/OSError delivery failures (reported as
502) so unrelated bugs still raise instead of being misreported as an
SMTP problem.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Comment thread apps/common/views.py

result = send_test_email(recipient)
response_status = status.HTTP_200_OK if result["sent"] else status.HTTP_502_BAD_GATEWAY
return Response(result, status=response_status)
@geourjoa

geourjoa commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Reopening to retrigger CI (initial pull_request webhook never fired for this PR).

@geourjoa geourjoa closed this Aug 5, 2026
@geourjoa geourjoa reopened this Aug 5, 2026
@geourjoa

geourjoa commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

CI status note: same issue as #150 — this PR's automatic `pull_request`-triggered checks never fired despite a push with fixes and a close/reopen cycle. Manually verified green via workflow_dispatch against this exact branch/commit:

Recommend re-running the standard PR checks once merged into the target branch, or investigating the webhook delivery issue separately.

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