feat(email): the report, invites, resets and test sends go through the outbox; only it talks SMTP (#5508)
#5508 "Every other email through the outbox: weekly report, invites, password resets, and the test buttons" (milestone 501). - outbox.send_each queues one email per reader (claimed, so the sender doesn't take it too) and tries them at once, for a page that answers with what happened; outbox.said words the result. attempt takes a cfg for a test of the form's unsaved settings and returns the settled rows. - Weekly report (scheduled and Send now) and invites: queued, tried at once; one the server couldn't take yet is retried for an hour. An invite that didn't go shows its link with the reason, as before. - Password reset: queued in the reset link's own transaction; the sender delivers it on its next tick. - Settings -> Notifications test email and a rule's Send test: queued and recorded with retry=False, tried once (System 156 ruling). - Removed mail.send, notifications._send_email and _smtp_send_sync; dispatch_notifications is webhook only. A guard asserts only the outbox (and smtp_open itself) opens an SMTP connection, with a self-test. Also fixes run 8941 (#5507's integration test): its Also-send-to addresses were "@test", which is_real_address rightly drops; they are example.com now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+13
-6
@@ -6,7 +6,6 @@ from datetime import datetime, timezone
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from steward.core import mail
|
||||
from steward.core import notifications as n
|
||||
from steward.core import reports
|
||||
|
||||
ALERT = {"rule_name": 'Disk <b>"root"</b> on web01', "state": "FIRING", "metric": "disk_used_pct",
|
||||
@@ -46,9 +45,8 @@ def test_every_colour_is_a_theme_value():
|
||||
|
||||
|
||||
async def _sent(monkeypatch, cfg, alert, to=(EXTRA_NY,)):
|
||||
out = []
|
||||
monkeypatch.setattr(n, "_smtp_send_sync", lambda c, msgs: out.extend(msgs))
|
||||
assert (await n._send_email(cfg, alert, list(to)))["sent"]
|
||||
"""The message each of `to` is handed for `alert`, as the outbox writes it."""
|
||||
out = [mail.message(cfg, r.address, *mail.alert_email(cfg, alert, r)) for r in to]
|
||||
return out[0] if len(to) == 1 else out
|
||||
|
||||
|
||||
@@ -140,12 +138,21 @@ async def test_the_report_is_sent_from_the_configured_address(monkeypatch):
|
||||
assert kind == "report"
|
||||
return [PERSON_NY, EXTRA_NY]
|
||||
|
||||
from types import SimpleNamespace
|
||||
from steward.core import outbox
|
||||
out = []
|
||||
|
||||
async def _send_each(app, kind, to, words, **kw):
|
||||
# Queued then tried at once (#5508); here every one is accepted.
|
||||
assert kind == "report" and kw.get("retry", True)
|
||||
out.extend(mail.message(app.config["SMTP"], r.address, *words(r)) for r in to)
|
||||
return [SimpleNamespace(recipient=r.address, state="sent", last_error=None) for r in to]
|
||||
|
||||
monkeypatch.setattr(reports, "build_report_data", _data)
|
||||
monkeypatch.setattr(reports, "recipients", _recipients)
|
||||
monkeypatch.setattr(n, "_smtp_send_sync", lambda c, msgs: out.extend(msgs))
|
||||
monkeypatch.setattr(outbox, "send_each", _send_each)
|
||||
ok, said = await reports.send_report(_App())
|
||||
assert ok and said == "Report sent to ann@example.com, ops@example.com."
|
||||
assert ok and said == "Sent to ann@example.com, ops@example.com."
|
||||
assert [(m["From"], m["To"]) for m in out] == [("alerts@example.com", "ann@example.com"),
|
||||
("alerts@example.com", "ops@example.com")]
|
||||
assert all(m.get_content_type() == "multipart/alternative" for m in out)
|
||||
|
||||
Reference in New Issue
Block a user