AI-powered email assistant that helps you manage Gmail efficiently through a command-line interface.
- 📧 Fetch Emails: Get your latest 10 emails with AI categorization
- ➡️ Pagination: Navigate through email pages using next page tokens
- ✉️ Send Emails: Compose and send new emails with AI-generated content
- ↩️ Smart Replies: Reply to emails using natural language identifiers
- 🧠 In-Memory Cache: Stores recent emails for quick reply access
- 🤖 AI Integration: Uses Google Gemini for email categorization and body generation
- Bun Runtime: Install from bun.sh
- Google API Credentials: Gmail API access with OAuth2
- Environment Variables: Google Gemini API key
# Clone the repository
git clone <your-repo-url>
cd EmailAgent
# Install dependencies using Bun
bun install- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Gmail API
- Create OAuth2 credentials and download as
clientSecret.json - Place
clientSecret.jsonin the project root
Create a .env file in the project root:
GOOGLE_API_KEY=your_gemini_api_key_hereGet your Gemini API key from Google AI Studio.
# Start Email Agent
bun run start
# Or run directly
bun run cli.js| Command | Description |
|---|---|
fetch |
Get your latest 10 emails |
next |
Get next page of emails |
send |
Send a new email |
reply |
Reply to an email from memory |
help |
Show help information |
exit |
Exit the application |
🤖 Email Agent > fetch
This will retrieve and categorize your latest 10 emails.
🤖 Email Agent > next
Use this after fetch to get the next 10 emails.
🤖 Email Agent > send
📮 Recipient email address: john@example.com
📝 Subject line: Project Update
💭 What should the email say?: Ask about the progress on phase 2 and timeline
🤖 Email Agent > reply
🔍 Enter email identifier: John Smith
💭 What should your reply say?: Confirm receipt and ask for meeting tomorrow
You can identify emails by:
- Sender name (e.g., "John Smith")
- Subject keywords (e.g., "Project Update")
- Gmail message ID
├── cli.js # Main CLI interface
├── agent/
│ └── agent.js # AI agent with LangChain integration
├── aiServices/
│ ├── memory.js # In-memory email cache
│ ├── categorize.js # Email categorization logic
│ └── tools/
│ ├── emailFetchTool.js # Email fetching tool
│ └── sendEmailTool.js # Email sending tool
└── services/
├── gmailService.js # Gmail API integration
└── extractLinks.js # Link extraction utility
The default user ID is user123. You can modify this in cli.js:
let currentUserId = "your_preferred_user_id";- Fetches 10 emails per page by default
- Stores last fetched emails in memory for replies
- Supports pagination with next page tokens
- Ensure
clientSecret.jsonis in project root - Run the CLI and follow OAuth flow to generate
token.json - Check that Gmail API is enabled in Google Cloud Console
- Gmail API has quotas - if you hit limits, wait before retrying
- Gemini API also has rate limits for AI features
- Email cache is cleared when CLI restarts
- Only the last 10 fetched emails are kept in memory
- Fork the repository
- Create your feature branch
- Make changes and test with Bun
- Submit a pull request
MIT License - see LICENSE file for details.
This project is optimized for Bun runtime:
# Install dependencies
bun install
# Run in development
bun run dev
# Run production
bun run startBun provides faster startup times and better performance compared to Node.js for this CLI application.