This project is a Python-based utility to connect to Gmail, authenticate using OAuth 2.0, and retrieve emails based on a custom search query. The results are processed and displayed in a Pandas DataFrame. The utility also extracts unique email addresses from senders and email content.
- OAuth 2.0 authentication using
credentials.json - Retrieve emails using Gmail API with custom search queries
- Display email metadata (sender, subject, date, snippet) in a DataFrame
- Extract and list unique email addresses from sender fields and message bodies
- Designed to work inside a Jupyter Notebook environment
- Go to Google Cloud Console.
- Create a new project (or select an existing one).
- Enable the Gmail API for the project.
- Navigate to APIs & Services > Credentials, click Create Credentials > OAuth 2.0 Client ID.
- Choose Desktop App as the application type.
- Download the
credentials.jsonfile and place it in the root directory of your project (same folder as the notebook).
- Clone this repository or download the notebook.
- Make sure
credentials.jsonis in the project directory. - Open tutorial_gmail_automation.ipynb in Jupyter Notebook and run all cells: -The first time, you will be prompted to authorize access via a browser. -Once authenticated, a token.json will be saved for future sessions.
- Modify the search_query variable inside the notebook to filter emails (e.g., 'subject:invoice', 'after:2024/01/01').