Files
ping-mee-self-service-platform/portal/mailer/management/commands/send_test_mail.py
T
ebbe.bassandClaude Sonnet 5.5 20510a73e5 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
2026-10-18 09:18:42 +02:00

29 lines
1.1 KiB
Python

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)