feat: add scheduler and mail outbox

SMTP adapter with TLS and a fake, outbox with retries, backoff, rate limit and restart safety, scheduler tick with job-run records started by gunicorn, and a send_test_mail command.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N3t4WL7bd9bdHHNjEsxzqC
This commit is contained in:
2026-10-18 09:18:42 +02:00
co-authored by Claude Sonnet 5.5
parent 0dc079a8ac
commit 20510a73e5
40 changed files with 1315 additions and 6 deletions
@@ -0,0 +1,28 @@
from django.core.management.base import BaseCommand, CommandError
from portal.mailer import services
from portal.mailer.models import OutboxMail
class Command(BaseCommand):
help = "Queue a test e-mail and send it now, to check the SMTP settings."
def add_arguments(self, parser):
parser.add_argument("recipient", help="E-mail address that should receive the test mail")
def handle(self, *args, recipient, **options):
try:
mail = services.enqueue("test", recipient)
except ValueError as exc:
raise CommandError(str(exc)) from exc
result = services.flush()
mail.refresh_from_db()
self.stdout.write(f"Outbox entry {mail.pk}: {mail.status} ({result})")
if mail.status == OutboxMail.Status.SENT:
self.stdout.write("The mail server accepted the message.")
elif mail.status == OutboxMail.Status.QUEUED:
self.stdout.write(f"Not sent yet, will be retried: {mail.last_error}")
raise SystemExit(1)
else:
self.stdout.write(f"Failed: {mail.last_error}")
raise SystemExit(1)