This project is a Python-based automation tool that connects to the Gmail API and Google Sheets API. It fetches real-time unread emails from a user's inbox, parses the relevant data (Sender, Subject, Date, Content), and logs them into a Google Sheet.
[Gmail Server] <-- (OAuth 2.0) --> [Python Script] <-- (OAuth 2.0) --> [Google Sheets] | | | (1. Fetch Unread) (2. Parse Data) (3. Append Row) | | (4. Mark as Read) ------------------------+
Flow:
- Auth: Script authenticates using OAuth 2.0 (User Credentials).
- Fetch: Requests only messages with label
UNREAD. - Parse: Decodes email body and extracts headers.
- Store: Appends data to Google Sheets.
- Update State: Marks email as
READin Gmail to prevent duplicate processing in future runs.
- Python 3.x
- Google Cloud Console Project with Gmail & Sheets APIs enabled.
credentials.json(OAuth Client ID).
-
Clone the repository:
git clone <your-repo-link> cd gmail-to-sheets
-
Install Dependencies:
pip install -r requirements.txt
-
Configure Credentials:
- Place your
credentials.jsonfile inside thecredentials/folder. - Note: This file is not included in the repo for security.
- Place your
-
Update Configuration:
- Open
config.py. - Add your
SPREADSHEET_ID.
- Open
Run the main script:
python src/main.py