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
33 lines
811 B
Python
33 lines
811 B
Python
"""The mail interface the outbox uses (AD-1, AD-11)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Protocol
|
|
|
|
|
|
class MailError(Exception):
|
|
"""Base class. Messages never contain the recipient or the text of the e-mail."""
|
|
|
|
|
|
class MailUnavailable(MailError):
|
|
"""The server could not take the message right now; trying again later may work."""
|
|
|
|
|
|
class MailRejected(MailError):
|
|
"""The server refused the message for good (for example an unknown recipient)."""
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class MailMessage:
|
|
sender: str
|
|
recipient: str
|
|
subject: str
|
|
body_text: str
|
|
|
|
|
|
class Mailer(Protocol):
|
|
def send(self, message: MailMessage) -> None:
|
|
"""Hand the message to the mail server, or raise MailUnavailable or MailRejected."""
|
|
...
|