API quản lý và đọc email từ các tài khoản Gmail.
- Python 3.7+
- FastAPI
- SQLAlchemy
- Uvicorn
- Các thư viện khác (xem requirements.txt)
- Clone repository:
git clone <repository-url>
cd <repository-name>- Tạo môi trường ảo:
python -m venv venv- Kích hoạt môi trường ảo:
- Windows:
venv\Scripts\activate- Linux/Mac:
source venv/bin/activate- Cài đặt các dependencies:
pip install -r requirements.txt- Chạy server với port mặc định (8000):
uvicorn app.main:app --reload- Hoặc chạy với port khác:
uvicorn app.main:app --reload --port 8080- Truy cập API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- POST
/accounts/email - Body:
{
"email": "your-email@gmail.com",
"secret": "your-app-password"
}Lưu ý: Với Gmail, bạn cần sử dụng App Password:
- Bật 2-Step Verification trong tài khoản Google
- Vào Google Account > Security > App Passwords
- Tạo App Password mới cho ứng dụng
- GET
/accounts/email - Query parameters:
- skip: số lượng bản ghi bỏ qua (mặc định: 0)
- limit: số lượng bản ghi tối đa (mặc định: 100)
- GET
/accounts/email/{email_account_id}
- PUT
/accounts/email/{email_account_id} - Body: giống như tạo mới
- DELETE
/accounts/email/{email_account_id}
- GET
/accounts/email/inbox/{email_account_id}
app/
├── main.py # FastAPI application và routes
├── database.py # Cấu hình database
├── models.py # SQLAlchemy models
├── schemas.py # Pydantic schemas
├── crud.py # Database operations
└── imap.py # IMAP email operations
API trả về các mã lỗi HTTP phổ biến:
- 400: Bad Request
- 404: Not Found
- 500: Internal Server Error
- Sử dụng App Password cho Gmail thay vì mật khẩu thông thường
- Không lưu trữ mật khẩu dưới dạng plain text
- Sử dụng HTTPS trong môi trường production
Mọi đóng góp đều được hoan nghênh. Vui lòng tạo issue hoặc pull request.
MIT