This is a Python application designed to interact with the Gmail API for various email management tasks. It provides a command-line interface (CLI) to send emails, retrieve email message IDs, and delete emails in bulk. The project uses OAuth2 for authentication and authorization with the Gmail API.
- Send Emails: Send an email by specifying the sender, recipient, subject, and message body.
- Retrieve Email Message IDs: Retrieve email message IDs based on a search query.
- Delete Emails: Delete emails in bulk based on a search query.
The project is structured into four main Python files:
-
authenticator.py:- Handles authentication with the Gmail API.
- Defines the permission scopes needed for the application.
- Manages the OAuth flow and token storage.
-
handler.py:- Contains utility functions to interact with the Gmail API.
- Functions to create, send, retrieve, and delete email messages.
-
flow.py:- Defines the user interaction flows for sending, deleting, and retrieving email messages.
- Guides the user through the necessary steps for each operation.
-
__main__.py:- The main entry point of the application.
- Manages the main menu and user interactions.
- Calls the appropriate functions from
flow.pybased on user input.
-
Install the required dependencies:
pip install google-auth google-auth-oauthlib google-api-python-client
-
Set up Google API credentials: Follow the instructions here
-
Run the application:
python __main__.py
-
Follow the on-screen prompts:
-
Main Menu:
- Send message.
- Delete message(s).
- Get message ID(s) and count.
- Exit.
-
Send Message:
- Enter sender email.
- Enter destination email.
- Enter subject.
- Enter message text.
-
Delete Message(s):
- Enter query (e.g.,
from: example@gmail.comorsubject: <string text>). - Confirm deletion.
- Enter query (e.g.,
-
Get Message ID(s) and Count:
- Enter query (e.g.,
from: example@gmail.comorsubject: <string text>).
- Enter query (e.g.,
-
- The application saves the user's access and refresh tokens in a
token.jsonfile for future use. - If the scopes are modified, delete the
token.jsonfile and re-authenticate. - The Gmail API has usage limits and quotas. Ensure your usage complies with Google's policies.
- When running the app, if you get an error saying 'token invalid/expired', delete the token.json file and re-run the app.
- It will then open a new tab in the browser (choose your email):

- Click 'continue'.

- Click 'continue', again.

- And finally, you should get a black page with the following notification:

Now you are ready to use the app.