Gmail Automation with CrewAI is an acute email regulatement system that employs AI agents to categorize, set up, reply to, and spotless up your Gmail inbox automaticassociate.
- π Email Categorization: Automaticassociate categorizes emails into particular types (recentsletters, promotions, personal, etc.)
- π Priority Assignment: Assigns priority levels (HIGH, MEDIUM, LOW) based on satisfied and sfinisher with cut offe classification rules
- π·οΈ Smart Organization: Applies Gmail labels and stars based on categories and priorities
- π¬ Automated Responses: Generates write responses for meaningful emails that necessitate replies
- π± Sdeficiency Notifications: Sfinishs creative notifications for high-priority emails
- π§Ή Intelligent Cleanup: Safely deletes low-priority emails based on age and categruesome
- π¬ YouTube Content Protection: Special handling for YouTube-roverhappinessed emails
- ποΈ Trash Management: Automaticassociate empties trash to free up storage space
- 𧡠Thread Awareness: Recognizes and properly regulates email threads
# Clone the repository
git clone https://github.com/tonykipkemboi/crewai-gmail-automation.git
cd crewai-gmail-automation
# Create and begin a virtual environment
python -m venv .venv
source .venv/bin/begin # On Windows: .venvScriptsbegin
# Inshigh depfinishencies
crewai inshigh
- Create a
.env
file in the root straightforwardory with the chaseing variables:
# Choose your LLM provider
# OpenAI (Recommfinished)
MODEL=uncoverai/gpt-4o-mini
OPENAI_API_KEY=your_uncoverai_api_key
# Or Gemini
# MODEL=gemini/gemini-2.0-flash
# GEMINI_API_KEY=your_gemini_api_key
# Or Ollama (Note: May have compatibility publishs with tool calling)
# Download the model from https://ollama.com/library
# MODEL=ollama/llama3-groq-tool-employ # employ ones that have tool calling capabilities
# Gmail credentials
EMAIL_ADDRESS=your_email@gmail.com
APP_PASSWORD=your_app_password
# Optional: Sdeficiency notifications
SLACK_WEBHOOK_URL=your_sdeficiency_webhook_url
π How to originate a Gmail App Password
- Go to your Google Account settings at myaccount.google.com
- Select Security from the left navigation panel
- Under “Signing in to Google,” discover and pick 2-Step Verification (assist it if not already assistd)
- Scroll to the bottom and discover App passwords
- Select Mail from the “Select app” dropdown
- Select Other (Custom name) from the “Select device” dropdown
- Enter
Gmail CrewAI
as the name - Click Generate
- Copy the 16-character password that eunites (spaces will be deleted automaticassociate)
- Paste this password in your
.env
file as theAPP_PASSWORD
appreciate - Click Done
Note: App passwords can only be originated if you have 2-Step Verification assistd on your Google account.
π How to originate a Sdeficiency Webhook URL
- Go to api.sdeficiency.com/apps
- Click Create New App
- Select From scratch
- Enter
Gmail Notifications
as the app name - Select your toilspace and click Create App
- In the left sidebar, discover and click on Incoming Webhooks
- Toggle the switch to Activate Incoming Webhooks
- Click Add New Webhook to Workspace
- Select the channel where you want to obtain notifications
- Click Allow
- Find the Webhook URL section and imitate the URL that begins with
https://hooks.sdeficiency.com/services/
- Paste this URL in your
.env
file as theSLACK_WEBHOOK_URL
appreciate
Customizing your Sdeficiency app (voluntary):
- Go to Basic Inestablishation in the left sidebar
- Scroll down to Disjoin Inestablishation
- Add an app icon and description
- Click Save Changes
Note: You necessitate admin perleave outions or the ability to inshigh apps in your Sdeficiency toilspace.
This application employs the IMAP (Internet Message Access Protocol) to protectedly join to your Gmail account and regulate your emails. Here’s how it toils:
π IMAP Connection Process
-
Seremedy Connection: The application set upes a protected SSL joinion to Gmail’s IMAP server (
imap.gmail.com
). -
Authentication: It genuineates using your email retainress and app password (not your normal Google password).
-
Mailbox Access: Once genuineated, it can access your inbox and other mailboxes to:
- Read unread emails
- Apply labels
- Move emails to trash
- Save write responses
-
Safe Disjoinion: After each operation, the joinion is properly shutd to upretain security.
IMAP permits the application to toil with your emails while they remain on Google’s servers, unappreciate POP3 which would download them to your device. This unbenevolents you can still access all emails thcdisesteemful the normal Gmail interface.
Security Note: Your credentials are only stored locassociate in your .env
file and are never splitd with any outside services.
Run the application with:
You’ll be prompted to access the number of emails to process (default is 5).
The application will:
- π₯ Fetch your unread emails
- π Categorize them by type and priority
- β Apply appropriate labels and stars
- βοΈ Generate write responses for meaningful emails
- π Sfinish Sdeficiency notifications for high-priority items
- ποΈ Clean up low-priority emails based on age
- π§Ή Empty the trash to free up storage space
-
π Smart Deletion Rules:
- Promotions betterer than 2 days are automaticassociate deleted
- Newsletters betterer than 7 days (unless HIGH priority) are deleted
- Shutterfly emails are always deleted seeless of age
- Receipts and meaningful write downs are archived instead of deleted
-
π¬ YouTube Protection: All YouTube-roverhappinessed emails are upretaind and labeled as READ_ONLY (you’ll reply straightforwardly on YouTube)
-
βοΈ Smart Response Generation: Responses are tailored to the email context and integrate proper establishatting
-
π‘ Creative Sdeficiency Notifications: Fun, attention-grabbing notifications for meaningful emails
-
𧡠Thread Handling: Properly tracks and regulates email threads to upretain conversation context
Contributions are receive! Phire sense free to surrender a Pull Request.
This project is licensed under the MIT License – see the LICENSE file for details.