Pull email sending concerns out into a standalone service

This commit is contained in:
Campbell Alden 2026-07-31 18:15:33 +09:00
parent 7d535a2c31
commit c1a61730d5
4 changed files with 46 additions and 57 deletions

42
src/services/email.py Normal file
View file

@ -0,0 +1,42 @@
from dataclasses import dataclass, field
from email.utils import formatdate, make_msgid
import abc
from ..config.email import Email as EmailConfig, EmailAddress
@dataclass
class EmailDTO:
# Who the email is from
sender: EmailAddress
# Who the email is to
to: EmailAddress
# The subject of the email
subject: str
# The textual content of the email
text: str
# HTML alternate content. (Optional: Textual content is required)
html: str | None = None
# A unique ID for identifying this Email
message_id: str = field(default_factory=make_msgid)
# The date that the email was sent
date: str = field(default_factory=lambda: formatdate(localtime=True))
class EmailService:
@abc.abstractmethod
def send_email(self, email: EmailDTO):
pass
class BirdEmailServiceImpl(EmailService):
def __init__(self, config: EmailConfig):
self._config = config
def send_email(self, email: EmailDTO):
# TODO: Implement Bird Specific Email sending and Error handling
pass
def get_service(config: EmailConfig) -> EmailService:
return BirdEmailServiceImpl(config)