Skip to content

iamvalson/email-digest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Automated Email Digest with WhatsApp Notifications

Project Overview

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.

Features

  • 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.pickle file.
  • Robust Error Handling: Includes retry logic for API calls and handles potential Twilio and other network-related errors.

Prerequisites

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.

Getting Started

1. Clone the Repository

Clone this repository to your local machine using Git:

git clone https://github.com/iamvalson/email-digest.git
cd email-digest
  1. 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
  1. 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

Configuration

1. Gmail API Credentials

  • Follow the official Google API Quickstart Guide to download your credentials.json file.
  • Place the credentials.json file 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.pickle file will be created automatically for future use.

2. Gemini API Key

  • Go to Google AI Studio to get your API key.
  • Open the email_reader.py script and paste your API key in the list_unread_emails function:
API_TOKEN = "YOUR_GEMINI_API_KEY_HERE"

Note: For production use, it is highly recommended to store API keys as environment variables for security.

3. Twilio Credentials

  1. Log in to your Twilio Console.
  2. Copy your Account SID and Auth Token.
  3. Open the email_reader.py script and paste your credentials into the send_message_via_twilio function:
sid = "YOUR_TWILIO_ACCOUNT_SID"
auth_token = "YOUR_TWILIO_AUTH_TOKEN"

Set Up Your Twilio WhatsApp Number

Update the to and from_ numbers in the send_message_via_twilio function with your personal WhatsApp number and your Twilio WhatsApp number, respectively.


Usage

Once everything is configured, run the script from your terminal:

python email_reader.py

The script will process the unread emails from the previous day and send you a WhatsApp message for each one.


Future Enhancements

Improved Importance Ranking

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.

Scheduled Automation

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.

Interactive Digest

Allow users to reply to the WhatsApp message to perform actions like marking an email as read or archiving it.

About

Scraps your daily emails and send the summary of it to your whatsapp ranking them in terms of importance

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages