A microservice-based email notification system that provides a REST API for sending various types of email notifications.
The system consists of the following components:
- API Service: A FastAPI application that receives email requests, formats them using Jinja2 templates, and sends them to Kafka.
- Worker Service: Consumes email messages from Kafka and sends them via SMTP.
- Kafka: Message broker for asynchronous processing of email requests.
- Zookeeper: Required for Kafka operation.
- PostgreSQL: Database for storing email-related data.
- Send email notifications for various events:
- Server deployment success notifications
- Server healthcheck failure alerts
- User email confirmations
- HTML email templates
- Asynchronous processing via Kafka
- Scalable microservice architecture
- Docker and Docker Compose
- Environment variables for email provider configuration
-
Clone the repository:
git clone <repository-url> cd mailing-api
-
Configure environment variables: Create a
.envfile with the following variables:MAILING_API_IMAGE_NAME=mailing-api:latest MAILING_WORKER_IMAGE_NAME=mailing-worker:latest EMAIL_PROVIDER_ADDRESS=your-email@example.com EMAIL_PROVIDER_HOST=smtp.example.com EMAIL_PROVIDER_USERNAME=your-username EMAIL_PROVIDER_PASSWORD=your-password EMAIL_PROVIDER_PORT=587 -
Start the services:
docker-compose up -d
For development purposes, use the development compose file:
docker-compose -f compose-dev.yaml up -dThis will:
- Mount local directories as volumes for hot-reloading
- Use development-specific run scripts
- Expose necessary ports for local development
-
POST /v1/emails/server-success-deploy
- Sends a notification about successful server deployment
- Requires: recipient email, subject, and deployment details
-
POST /v1/emails/server-healthcheck-failed
- Sends a notification about failed server healthchecks
- Requires: recipient email, subject, and server details
-
POST /v1/emails/email-confirmation
- Sends an email confirmation message
- Requires: recipient email, subject, and confirmation details
The system can be configured using environment variables:
MAILING_WORKER_HOST: Hostname for the worker serviceMAILING_WORKER_PORT: Port for the worker serviceMAILING_WORKER_DB_*: Database connection parametersEMAIL_PROVIDER_*: Email provider configuration