- Python 3.9 or higher
- Virtual Environment
- Google Account: You'll need a Google account to access the Gmail API.
- Google Cloud Platform (GCP) Account: You need to have a GCP account to create a project and enable the Gmail API.
-
Clone the repository:
git clone [email protected]:sarathak/emailrules.git
-
Navigate to the project directory:
cd <project_directory>
-
Create a virtual environment:
python3 -m venv venv
-
Activate the virtual environment:
source venv/bin/activate
-
Install project dependencies:
pip install -r requirements.txt
Follow these steps to set up Gmail API:
- Go to the Google Cloud Console.
- Click on the project selector dropdown and create a new project.
- Give your project a name and click Create.
- In the Google Cloud Console, navigate to the APIs & Services > Library page.
- Search for "Gmail API" and click on it.
- Click the Enable button.
- In the Google Cloud Console, navigate to the APIs & Services > Credentials page.
- Click on Create Credentials > OAuth client ID.
- Select "Desktop app" as the application type.
- Give your OAuth client a name.
- Click Create.
- After creation, click on the OAuth client you just created from the list.
- Download credential file and putin to project directory as credentials.json
python fetch_emails.py
- Create rules as
rules.json
in project directory:[ { "description": "Rule 1", "conditions": "all", "properties": [ { "field": "from", "predicate": "contains", "value": "[email protected]" } ], "actions": [ { "operation": "move", "destination": "bin" } ] } ]
- Execute script file
python execute_rules.py
python tests.py