A Python script that cleans up Gmail inbox by automatically deleting emails older than a year.
- Search and Delete: Searches for emails older than a year and moves them to the trash.
- User Confirmation: Asks for user confirmation before performing deletion.
- Automatic Authentication: Handles OAuth2 authentication with Gmail API.
- Gmail API credentials
-
Clone the repository:
git clone https://github.com/nourhan031/gmail-cleaner.git cd gmail-cleaner -
Create and activate a virtual environment (optional but recommended):
python -m venv venv venv\Scripts\activate
-
Install the required packages:
pip install -r requirements.txt
-
Set up Gmail API credentials:
- Go to the Google Cloud Console.
- Enable the Gmail API.
- Create OAuth 2.0 Client IDs credentials.
- Download the
client_secret.jsonfile and place it in the project directory.
-
Run the script:
python main.py
-
Authenticate:
- On the first run, the script will open a browser window for you to log in to your Google account and authorize the application.
- After authentication, a
token.jsonfile will be created to store the access and refresh tokens.
-
Confirm deletion:
- The script will ask for your confirmation before deleting the emails.