feat: "Email sent" column and per-event copy-to-organizer BCC

Organizers had no way to see whether a ticket email went out short of
reading the Postfix journal, and no copy of what the attendee received —
LNbits submits over SMTP, so nothing lands in a Sent folder.

- Admin ticket table gains an "Email sent" column derived from
  `extra.email_notification_sent` ("✓ sent" / "not sent" / "unpaid" /
  "no email").
- `extra.copy_to_organizer`: BCC every ticket email to the event's
  reply-to address (explicit, else the owner's account email) on the SMTP
  envelope only — no Bcc/To header, and skipped when the buyer *is* that
  address. Toggle sits with the other delivery switches in the admin form.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYwoAkZZmXMMmaBp4WGUBo
This commit is contained in:
Padreug 2026-09-13 17:40:49 +02:00
commit a44de1aa3f
5 changed files with 73 additions and 1 deletions

View file

@ -1,5 +1,6 @@
from datetime import datetime, timezone
import pytest
from lnbits.settings import settings
from ..models import Event, Ticket
@ -143,3 +144,33 @@ def test_blank_reply_to_email_is_none():
assert EventExtra(reply_to_email="").reply_to_email is None
assert EventExtra(reply_to_email=" ").reply_to_email is None
assert EventExtra(reply_to_email="a@b.example").reply_to_email == "a@b.example"
@pytest.mark.asyncio
async def test_copy_to_organizer_is_bcc_on_the_envelope_only(monkeypatch):
from .. import services
monkeypatch.setattr(settings, "lnbits_email_notifications_enabled", True)
monkeypatch.setattr(
settings, "lnbits_email_notifications_email", "oyez@example.org"
)
monkeypatch.setattr(
settings, "lnbits_email_notifications_server", "smtp.example.org"
)
monkeypatch.setattr(settings, "lnbits_email_notifications_port", 587)
monkeypatch.setattr(settings, "lnbits_email_notifications_username", "")
monkeypatch.setattr(settings, "lnbits_email_notifications_password", "x")
sent = {}
def fake_smtp_send(
server, port, username, password, from_email, recipients, payload
):
sent.update(recipients=recipients, payload=payload)
monkeypatch.setattr(services, "_smtp_send", fake_smtp_send)
await services._send_ticket_email_notification(
["buyer@example.com"], "text", "Subj", None, bcc=["organizer@example.org"]
)
assert sent["recipients"] == ["buyer@example.com", "organizer@example.org"]
assert "organizer@example.org" not in sent["payload"] # no Bcc/To leak
assert "To: buyer@example.com" in sent["payload"]