Gmail Reader is a Go script designed to mark emails as read. Nothing serious, just something I hacked together a couple of months ago to mark all my unread emails as read. I thought it might be useful to someone else, so I decided to share it.
Before using the script, ensure you have set up the necessary credentials:
- Go to the Google Cloud Console.
- Create or select a project.
- Enable the Gmail API.
- Create OAuth 2.0 Client ID credentials.
- Download the credentials as
credentials.json
and place it in the project directory.
-
Download the Binary:
-
Authentication:
- For the first run, follow on-screen instructions to authenticate and mark emails as read.
- To switch accounts, delete
token.json
and re-run the script.
-
Run the Script:
- On Windows:
.\gmail-reader.exe
- On macOS/Linux:
./gmail-reader
- On Windows:
-
Authorization Page:
- Opened in your default browser, log in to the Gmail account to grant permissions.
-
Grant Permissions:
- Click "Allow" to grant necessary permissions.
-
Extract the Code:
- Copy the authentication code from the URL after granting permissions.
-
Paste the Code:
- Return to the terminal and paste the code when prompted.
-
Complete Authentication:
- Press Enter to finish the process.
-
Continue Script Execution:
- The script proceeds to mark emails as read.
If encountering an "invalid grant" error:
-
Check Credentials:
- Verify
credentials.json
correctness.
- Verify
-
Generate New Credentials:
- In Google Cloud Console, recreate OAuth credentials.
-
Verify OAuth 2.0 Consent Screen:
- Ensure proper configuration with required scopes.
-
Clear Cached Tokens:
- Delete
token.json
and re-run the script.
- Delete
-
Check System Date and Time:
- Ensure accuracy; incorrect date/time can affect OAuth token validation.
-
Verify Internet Connection:
- Stable internet is required for communication with Google's servers.
-
Regenerate OAuth Token:
- Follow on-screen instructions during authentication.
If issues persist, open an issue in this repository.
This project is licensed under the MIT License. See LICENSE for details.