This project is an automated email digest system designed to simplify your daily inbox management. The Python script connects to your Gmail account, identifies unread emails from the previous day, and uses the Google Gemini API to summarize their content. It then sends a concise, categorized digest directly to your phone via Twilio WhatsApp, allowing you to quickly check important messages without opening your email client.
- Automated Email Fetching: Fetches unread emails from the previous day using the Gmail API.
- AI-Powered Summarization: Uses the Gemini API to create a concise summary of each email's body.
- Urgency Analysis: Prompts Gemini to determine if an email requires immediate attention and categorizes it with a "Yes" or "No" rating.
- WhatsApp Notifications: Delivers the summarized and categorized email digest directly to your WhatsApp number using the Twilio API.
- Secure Authentication: Handles OAuth 2.0 authentication with Gmail, storing credentials securely in a local
token.picklefile. - Robust Error Handling: Includes retry logic for API calls and handles potential Twilio and other network-related errors.
Before you begin, ensure you have the following:
- Python 3.6+ installed on your system.
- A Google account with access to Gmail.
- A Google Cloud Project with the Gmail API enabled.
- A Google AI Studio API Key for the Gemini API.
- A Twilio account with an active WhatsApp sandbox or a Twilio phone number.
Clone this repository to your local machine using Git:
git clone https://github.com/iamvalson/email-digest.git
cd email-digest- Set Up a Virtual Environment It's highly recommended to use a virtual environment to manage project dependencies.
python -m venv venv
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate- Install Dependencies Install all the required Python libraries using pip:
pip install google-api-python-client google-auth-oauthlib google-auth-httplib2 google-generativeai twilio- Follow the official Google API Quickstart Guide to download your
credentials.jsonfile. - Place the
credentials.jsonfile in your project's root directory. - The first time you run the script, a browser window will open for you to grant access to your Gmail account. A
token.picklefile will be created automatically for future use.
- Go to Google AI Studio to get your API key.
- Open the
email_reader.pyscript and paste your API key in thelist_unread_emailsfunction:
API_TOKEN = "YOUR_GEMINI_API_KEY_HERE"Note: For production use, it is highly recommended to store API keys as environment variables for security.
- Log in to your Twilio Console.
- Copy your Account SID and Auth Token.
- Open the
email_reader.pyscript and paste your credentials into thesend_message_via_twiliofunction:
sid = "YOUR_TWILIO_ACCOUNT_SID"
auth_token = "YOUR_TWILIO_AUTH_TOKEN"Update the to and from_ numbers in the send_message_via_twilio function with your personal WhatsApp number and your Twilio WhatsApp number, respectively.
Once everything is configured, run the script from your terminal:
python email_reader.pyThe script will process the unread emails from the previous day and send you a WhatsApp message for each one.
Currently, the script relies on the LLM to categorize emails. A more robust solution would involve a separate Python function with more specific, rule-based logic to determine importance, independent of the LLM's response.
Set up a cron job (on Linux/macOS) or a scheduled task (on Windows) to automatically run the script every day at a specific time.
Allow users to reply to the WhatsApp message to perform actions like marking an email as read or archiving it.