Skip to content

D-RubyIV/fastmail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Email Accounts API

API quản lý và đọc email từ các tài khoản Gmail.

Yêu cầu hệ thống

  • Python 3.7+
  • FastAPI
  • SQLAlchemy
  • Uvicorn
  • Các thư viện khác (xem requirements.txt)

Cài đặt

  1. Clone repository:
git clone <repository-url>
cd <repository-name>
  1. Tạo môi trường ảo:
python -m venv venv
  1. Kích hoạt môi trường ảo:
  • Windows:
venv\Scripts\activate
  • Linux/Mac:
source venv/bin/activate
  1. Cài đặt các dependencies:
pip install -r requirements.txt

Chạy ứng dụng

  1. Chạy server với port mặc định (8000):
uvicorn app.main:app --reload
  1. Hoặc chạy với port khác:
uvicorn app.main:app --reload --port 8080
  1. Truy cập API documentation:

API Endpoints

1. Tạo tài khoản email

  • 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:

  1. Bật 2-Step Verification trong tài khoản Google
  2. Vào Google Account > Security > App Passwords
  3. Tạo App Password mới cho ứng dụng

2. Lấy danh sách tài khoản email

  • 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)

3. Lấy thông tin một tài khoản email

  • GET /accounts/email/{email_account_id}

4. Cập nhật tài khoản email

  • PUT /accounts/email/{email_account_id}
  • Body: giống như tạo mới

5. Xóa tài khoản email

  • DELETE /accounts/email/{email_account_id}

6. Đọc inbox của tài khoản email

  • GET /accounts/email/inbox/{email_account_id}

Cấu trúc dự án

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

Xử lý lỗi

API trả về các mã lỗi HTTP phổ biến:

  • 400: Bad Request
  • 404: Not Found
  • 500: Internal Server Error

Bảo mật

  • 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

Đóng góp

Mọi đóng góp đều được hoan nghênh. Vui lòng tạo issue hoặc pull request.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages