A simple FastAPI-based mailbox API for managing and sending emails. This mailbox system using Kafka involves building a scalable and efficient messaging system where users can send, receive, and store messages.
- Send emails via API endpoints
- Manage mailbox data
- FastAPI backend
- Python 3.8+
- pip
-
Clone the repository:
git clone https://github.com/your-username/mailbox_api.git cd mailbox_api -
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
uvicorn main:app --reload- The API will be available at: http://localhost:8000
- Interactive docs: http://localhost:8000/docs
- Edit
config.pyor environment variables as needed for email settings.
To enable email queuing and caching, you may need to run Kafka and Redis:
docker run -d --name kafka -p 9092:9092 -e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092 bitnami/kafka:latestNote: You may also need to run Zookeeper:
docker run -d --name zookeeper -p 2181:2181 bitnami/zookeeper:latest
docker run -d --name redis -p 6379:6379 redis:latestMake sure your application is configured to connect to these services as needed.
If you prefer not to use Docker, you can run Kafka and Redis directly on your system:
Kafka requires Zookeeper. Download and extract Apache Zookeeper:
tar -xzf apache-zookeeper-*.tar.gz
cd apache-zookeeper-*/
bin/zkServer.sh startor
cd kafka_2.13-3.6.1
bin/zookeeper-server-start.sh config/zookeeper.propertiesDownload and extract Apache Kafka:
tar -xzf kafka_*.tgz
cd kafka_*/
bin/kafka-server-start.sh config/server.propertiesor
cd kafka_2.13-3.6.1
bin/kafka-server-start.sh config/server.propertiesInstall Redis using your package manager:
- Ubuntu/Debian:
sudo apt update sudo apt install redis-server sudo systemctl start redis
- macOS (with Homebrew):
brew install redis brew services start redis
Refer to the official documentation for more details on configuration and management.
Alembic is used for handling database migrations.
pip install alembic
alembic init alembicEdit alembic.ini and set your database URL:
sqlalchemy.url = postgresql://postgres:postgres@postgres:5432/mailbox_dbGenerate and apply your initial migration:
alembic revision --autogenerate -m "init schema"
alembic upgrade headFirst you have to run kafka
cd kafka_2.13-3.6.1
bin/zookeeper-server-start.sh config/zookeeper.propertiescd kafka_2.13-3.6.1
bin/kafka-server-start.sh config/server.propertiesThen you should start postgresql server and radis
sudo systemctl start postgresql
sudo systemctl start redisNow You can run your FastApi App
- Go to you python venv
source venv/bin/activate- Run your app
uvicorn app.main:app --reloadThen you should run your kafka consumer service
- Go to you python venv and then
python consumer_service.pyNow you test your FastApi mailbox app using below url
- The API will be available at: http://localhost:8000
- Interactive docs: http://localhost:8000/docs
MIT License