feat(newsletter): Add subscription confirmation email functionality
All checks were successful
CI / test (3.11) (push) Successful in 9m26s
CI / build-image (push) Successful in 49s

- Implemented `send_subscription_confirmation` function to send a confirmation email upon subscription.
- Added a default HTML template for the confirmation email in settings.
- Updated the newsletter management page to handle subscription and unsubscription actions.
- Created new templates for embedding contact and newsletter forms.
- Added styles for the new templates and unified CSS styles across the application.
- Updated tests to reflect changes in the newsletter management API endpoints.
This commit is contained in:
2025-10-30 12:38:26 +01:00
parent f7695be8ef
commit 56840ac313
24 changed files with 897 additions and 449 deletions

View File

@@ -61,11 +61,12 @@ Access the admin interface at `http://127.0.0.1:5002/auth/login` using the confi
- `GET /api/contact`: retrieves contact form submissions (admin only, requires authentication). Supports pagination (`page`, `per_page`), filtering (`email`, `date_from`, `date_to`), and sorting (`sort_by`, `sort_order`).
- `GET /api/contact/<id>`: retrieves a specific contact submission by ID (admin only).
- `DELETE /api/contact/<id>`: deletes a contact submission by ID (admin only).
- `POST /api/newsletter`: subscribes an address and optional metadata to the newsletter list.
- `POST /api/newsletter`: subscribes an address and optional metadata to the newsletter list. Sends a confirmation email if SMTP is configured.
- `DELETE /api/newsletter`: unsubscribes an email address from the newsletter list.
- `PUT /api/newsletter`: updates a subscriber's email address (requires `old_email` and `new_email`).
- `GET /api/newsletter/manage`: displays HTML form for newsletter subscription management.
- `POST /api/newsletter/manage`: processes subscription management actions (subscribe, unsubscribe, update).
- `GET /newsletter/unsubscribe/confirmation`: displays unsubscription confirmation page.
- `GET /health`: lightweight database connectivity check used for container health monitoring.
- `GET /metrics`: Prometheus-compatible metrics endpoint (requires `ENABLE_REQUEST_LOGS` for detailed tracing).
- `GET /admin/api/settings`: retrieves all application settings (admin only).
@@ -77,6 +78,41 @@ Access the admin interface at `http://127.0.0.1:5002/auth/login` using the confi
- `POST /admin/api/newsletters/<id>/send`: sends a newsletter to all subscribers (admin only).
- `GET /admin/api/contact`: retrieves contact form submissions with pagination, filtering, and sorting (admin only).
- `DELETE /admin/api/contact/<id>`: deletes a contact submission by ID (admin only).
- `GET /embed/contact`: serves an HTML page with a contact form that can be embedded in an iframe on external sites.
- `GET /embed/newsletter`: serves an HTML page with a newsletter subscription form that can be embedded in an iframe on external sites.
## Embeddable Forms
The application provides embeddable contact and newsletter subscription forms that can be integrated into other websites via iframe.
- `GET /embed/contact`: serves an HTML page with a contact form that can be embedded in an iframe on external sites.
- `GET /embed/newsletter`: serves an HTML page with a newsletter subscription form that can be embedded in an iframe on external sites.
To embed the contact form on another website, use the following HTML code:
```html
<iframe
src="https://your-server-domain/embed/contact"
width="600"
height="400"
frameborder="0"
allowfullscreen
></iframe>
```
To embed the newsletter subscription form:
```html
<iframe
src="https://your-server-domain/embed/newsletter"
width="600"
height="300"
frameborder="0"
allowfullscreen
></iframe>
```
Replace `https://your-server-domain` with your actual server URL. The iframe codes are available in the admin settings page for easy copying.
## Running With Docker
@@ -203,3 +239,13 @@ SMTP integration tests are skipped unless `RUN_SMTP_INTEGRATION_TEST=1` and vali
- When the default branch (`main`) runs and registry secrets (`REGISTRY_URL`, `REGISTRY_USERNAME`, `REGISTRY_PASSWORD`) are configured in Gitea, the workflow logs in and pushes both `latest` and commit-specific image tags.
- Import or mirror the required reusable actions (`actions/checkout`, `actions/setup-python`, and the Docker actions) into your Gitea instance so that the workflow can resolve them.
- For production use, deploy the container behind a load balancer or reverse proxy and supply the appropriate environment variables.
## Email Templates
The application supports customizable email templates for newsletter confirmations. The confirmation email template can be edited through the admin settings page under the dynamic settings management. The template uses HTML format and should include an unsubscribe link for compliance with email regulations.
Default confirmation email includes:
- Welcome message
- Unsubscribe instructions with link to `/newsletter/manage`
- Customizable HTML content