## ADDED Requirements ### Requirement: Outbound email delivery The system SHALL send outbound emails via direct SMTP connection to a configured mail server. Configuration includes SMTP host, port, and optional credentials. #### Scenario: Send email - **WHEN** the system needs to send an email (password reset, notification, etc.) - **THEN** it connects to the configured SMTP server and delivers the message #### Scenario: SMTP failure - **WHEN** the SMTP connection fails - **THEN** the email is queued for retry and the failure is logged ### Requirement: Mail queue The system SHALL maintain a persistent mail queue in the database. Emails are enqueued by application code and dequeued by the backend worker for delivery. Failed deliveries are retried with backoff. #### Scenario: Enqueue email - **WHEN** application code requests an email be sent - **THEN** the email is stored in the mail queue with recipient, subject, body, and status "pending" #### Scenario: Backend worker processes queue - **WHEN** the backend worker checks the mail queue - **THEN** it attempts delivery of all pending emails and updates their status (sent or failed with retry count) ### Requirement: Mail templates The system SHALL support named mail templates with placeholder substitution. Templates are stored in the database per organization. Placeholders use a simple token syntax (e.g., `%UserName%`, `%OrganizationName%`). #### Scenario: Render template - **WHEN** an email is composed using a template name and substitution values - **THEN** the template body is fetched, placeholders are replaced, and the result is enqueued