# Routine Email Service ## Overview This service sends automated email reports about account records at scheduled times using cron. It retrieves account records from a PostgreSQL database, formats them into an HTML email, and sends them to specified recipients. ## Environment Setup The service requires the following environment variables: ### Email Configuration - `EMAIL_HOST`: SMTP server address (e.g., "10.10.2.34") - `EMAIL_USERNAME`: Email sender address (e.g., "example@domain.com") - `EMAIL_PASSWORD`: Email password (sensitive) - `EMAIL_PORT`: SMTP port (e.g., 587) - `EMAIL_SEND`: Flag to enable/disable email sending (1 = enabled) ### Database Configuration - `DB_HOST`: PostgreSQL server address (e.g., "10.10.2.14") - `DB_USER`: Database username (e.g., "postgres") - `DB_PASSWORD`: Database password (sensitive) - `DB_PORT`: Database port (e.g., 5432) - `DB_NAME`: Database name (e.g., "postgres") ## Cron Job Configuration The service is configured to run daily at 11:00 Istanbul Time (08:00 UTC). This is set up in the entrypoint.sh script. ## Docker Container Setup ### Key Files 1. **Dockerfile**: Defines the container image with Python and cron 2. **entrypoint.sh**: Container entrypoint script that: - Creates an environment file (/env.sh) with all configuration variables - Sets up the crontab to run run_app.sh at the scheduled time - Starts the cron service - Tails the log file for monitoring 3. **run_app.sh**: Script executed by cron that: - Sources the environment file to get all configuration - Exports variables to make them available to the Python script - Runs the Python application - Logs environment and execution results ### Environment Variable Handling Cron jobs run with a minimal environment that doesn't automatically include Docker container environment variables. Our solution: 1. Captures all environment variables from Docker to a file at container startup 2. Has the run_app.sh script source this file before execution 3. Explicitly exports all variables to ensure they're available to the Python script ## Logs Logs are written to `/var/log/cron.log` and can be viewed with: ```bash docker exec routine_email_service tail -f /var/log/cron.log ``` ## Manual Execution To run the service manually: ```bash docker exec routine_email_service /run_app.sh ``` ## Docker Compose Configuration In the docker-compose.yml file, the service needs an explicit entrypoint configuration: ```yaml entrypoint: ["/entrypoint.sh"] ``` This ensures the entrypoint script runs when the container starts.