This Python project automatically reads unread emails from your Gmail inbox and logs them into a Google Sheets spreadsheet for easy tracking and analysis.
- Reads unread emails from Gmail inbox
- Extracts the following email details:
- Sender
- Subject
- Timestamp
- Email body
- Supports email filtering:
- Sender
- Subject
- Keywords
- Converts HTML email content to plain text for clean storage
- Appends extracted data to Google Sheets
- Tracks processed emails to avoid duplicate entries
- Python 3.9 or above
- Google Cloud Account
- Gmail Account
- Go to Google Cloud Console
- Open the search bar
- Search for Gmail API → Enable it
- Search for Google Sheets API → Enable it
- Open ☰ Menu → APIs & Services → OAuth Consent Screen
- Click Configure Consent Screen
- Select External user type
- Fill required details:
- App name: Gmail to Sheets Automation
- User support email: Your email
- Developer contact email: Your email
- Click Save and Continue
- Complete the setup and finish
- Go to ☰ Menu → APIs & Services → OAuth Consent Screen → Clients
- Click Create Client
- Choose Application type: Desktop App
- Name it:
Gmail Email Logs - Click Create
- Download the credentials JSON file
- Rename it to
credentials.json - Place it inside the project root/credentials directory
- Go to ☰ Menu → APIs & Services → OAuth Consent Screen → Audience
- Scroll to Test Users
- Click ADD USERS
- Add your Gmail address
- Click SAVE
- Click PUBLISH APP
- Click CONFIRM
- Wait 2–5 minutes for changes to propagate
pip install -r requirements.txtpython setup.py- A browser window will open for OAuth authentication Grant required permissions Return to terminal and choose:
- Use an existing spreadsheet OR Create a new spreadsheet
- If using an existing spreadsheet, provide the Spreadsheet ID in config.json
python main.pyOn success, a confirmation message will be displayed.
Email data is logged into Google Sheets
Access it via:
https://docs.google.com/spreadsheets/d/{spreadsheet_id}Or find it directly in your Google Drive
- Only unread emails are processed
- Already processed emails are skipped automatically using state.json
- Ensure credentials.json and config.json are properly configured