This utility script is designed to mark unread emails as read in your Gmail account using Python and Google's Gmail API. Please follow the setup instructions carefully before running the script.
To use this script, you must have Python installed on your system and access to the Gmail API, along with OAuth 2.0 credentials for authentication.
To interact with Gmail, you must enable the API and obtain the necessary credentials:
- Visit the Google Developers Console.
- Start a new project by clicking
Create Project
, provide a name for your project, and then clickCreate
. - Once the project is created, navigate to the
Dashboard
section. - Click on
+ ENABLE APIS AND SERVICES
. - In the API Library, search for "Gmail API" and enable it for your project.
Now you need to create and download the credentials to allow your script to access your Gmail account securely:
- Go to the
APIs & Services > Credentials
panel in the Google Developers Console. - Click on
Create Credentials
and chooseOAuth client ID
. - If prompted, configure the consent screen, and provide the required information about your application.
- Choose
Application type
asDesktop app
and give it a name. - Upon creation, click the
Download
button next to your newly created credentials to obtain the JSON file. - Save this file as
credentials.json
in your project directory.
You need to install the Google client library for Python to interact with the Gmail API. Execute the following command:
pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
The script automates the process of logging into the Gmail API using the provided credentials, searching for all unread messages, and iteratively removing the 'UNREAD' label from them.
With the setup complete, you can run the script using the following command:
python main.py
- Caution: Running this script will modify the read status of your emails on your Gmail account. Please use it responsibly and review the script before executing.
- Security: Your email data is sensitive. Keep your
credentials.json
andtoken.json
files secure, and never share them. - Testing: It's recommended to test the script on a small number of emails or a test account before applying it to your primary email account.
- Errors and Rate Limits: If you encounter any errors or rate limits from the Gmail API, the script includes an exponential backoff strategy to retry the request after a certain interval.
For further assistance or feedback, please reach out through the Issues section of this repository.