Skip to content

domain.protocols.email_service_protocol

src.domain.protocols.email_service_protocol

EmailServiceProtocol - Domain protocol for email operations.

This protocol defines the interface for sending emails. Infrastructure provides concrete implementations (Stub, AWS SES, etc.).

Following hexagonal architecture: - Domain defines what it needs (protocol/port) - Infrastructure provides implementation (adapter) - Application layer uses protocol, not concrete implementation

Classes

EmailServiceProtocol

Bases: Protocol

Protocol for email sending operations.

Defines the contract that all email service implementations must satisfy. Used for sending verification emails, password reset emails, etc.

Implementations
  • StubEmailService: src/infrastructure/email/stub_email_service.py (dev/test)
  • SESEmailService: src/infrastructure/email/ses_email_service.py (production)
Source code in src/domain/protocols/email_service_protocol.py
class EmailServiceProtocol(Protocol):
    """Protocol for email sending operations.

    Defines the contract that all email service implementations must satisfy.
    Used for sending verification emails, password reset emails, etc.

    Implementations:
        - StubEmailService: src/infrastructure/email/stub_email_service.py (dev/test)
        - SESEmailService: src/infrastructure/email/ses_email_service.py (production)
    """

    async def send_verification_email(
        self,
        to_email: str,
        verification_url: str,
    ) -> None:
        """Send email verification email.

        Args:
            to_email: Recipient email address.
            verification_url: Full URL with verification token.
        """
        ...

    async def send_password_reset_email(
        self,
        to_email: str,
        reset_url: str,
    ) -> None:
        """Send password reset email.

        Args:
            to_email: Recipient email address.
            reset_url: Full URL with password reset token.
        """
        ...

    async def send_password_changed_notification(
        self,
        to_email: str,
    ) -> None:
        """Send notification that password was changed.

        Args:
            to_email: Recipient email address.
        """
        ...
Functions
send_verification_email async
send_verification_email(
    to_email: str, verification_url: str
) -> None

Send email verification email.

Parameters:

Name Type Description Default
to_email str

Recipient email address.

required
verification_url str

Full URL with verification token.

required
Source code in src/domain/protocols/email_service_protocol.py
async def send_verification_email(
    self,
    to_email: str,
    verification_url: str,
) -> None:
    """Send email verification email.

    Args:
        to_email: Recipient email address.
        verification_url: Full URL with verification token.
    """
    ...
send_password_reset_email async
send_password_reset_email(
    to_email: str, reset_url: str
) -> None

Send password reset email.

Parameters:

Name Type Description Default
to_email str

Recipient email address.

required
reset_url str

Full URL with password reset token.

required
Source code in src/domain/protocols/email_service_protocol.py
async def send_password_reset_email(
    self,
    to_email: str,
    reset_url: str,
) -> None:
    """Send password reset email.

    Args:
        to_email: Recipient email address.
        reset_url: Full URL with password reset token.
    """
    ...
send_password_changed_notification async
send_password_changed_notification(to_email: str) -> None

Send notification that password was changed.

Parameters:

Name Type Description Default
to_email str

Recipient email address.

required
Source code in src/domain/protocols/email_service_protocol.py
async def send_password_changed_notification(
    self,
    to_email: str,
) -> None:
    """Send notification that password was changed.

    Args:
        to_email: Recipient email address.
    """
    ...