MAILGENIE is a feature-rich, self-hosted email management system designed to act as a personal unified inbox. It connects to multiple IMAP accounts, synchronizes emails in real-time, and provides a powerful interface for searching, filtering, and managing your emails. The system leverages AI for intelligent email categorization and smart replies, and it is built as a full-stack application with a Node.js backend and a React frontend.
- User Authentication: Secure user signup, login, and logout using JWTs.
- IMAP Account Management: Add, view, update, and delete IMAP account configurations.
- Real-time Email Synchronization: Connects to multiple IMAP accounts and uses the
IDLEcommand to listen for new emails in real-time. It fetches the last 30 days of emails on initial sync. - AI-Powered Email Categorization: Uses the Google Gemini API to automatically categorize emails into
Interested,Meeting Booked,Not Interested,Spam, orOut of Office. - AI-Powered Smart Replies: Generates context-aware smart replies using a Retrieval-Augmented Generation (RAG) system with a Faiss vector store.
- Searchable Email Storage: Indexes all emails in a locally hosted Elasticsearch instance for powerful full-text search and filtering by account, folder, or category.
- Automated Notifications: Sends Slack notifications and triggers external webhooks for new emails categorized as "Interested".
- Unified Email Dashboard: Displays an aggregated list of emails with their subject, sender, and AI-generated category.
- Advanced Filtering and Searching: Allows users to filter emails by category and perform full-text searches across all accounts.
- AI Reply Generation: A "Generate Reply" button provides AI-suggested replies for any email.
- Account Management: A settings page to view and manage configured email accounts.
| Area | Technology |
|---|---|
| Backend | Node.js, TypeScript, Express.js, PostgreSQL, Drizzle ORM, JWT, imapflow |
| Frontend | React, TypeScript, Chakra UI, react-query, axios, Vite |
| DevOps | Docker, Docker Compose |
- Node.js (v18 or later)
- Docker and Docker Compose
- npm
-
Clone the repository:
git clone <your-repository-url> cd MailGenie
-
Install dependencies:
npm install
-
Set up environment variables:
This project uses a
.envfile for environment variables. You can create your own by copying the example file:cp .env.example .env
Then, update the newly created
.envfile with your specific configurations forDATABASE_URL,ELASTICSEARCH_URL,ELASTICSEARCH_USERNAME,ELASTICSEARCH_PASSWORD,GEMINI_API_KEY,SLACK_WEBHOOK_URL, andWEBHOOK_URL. Refer to.env.examplefor the list of required variables. -
Start the database and Elasticsearch:
Run the following command to start the PostgreSQL and Elasticsearch containers in the background:
docker compose up -d
-
Run database migrations:
Apply the database schema to your PostgreSQL instance:
npm run db:generate npm run db:push
-
Run the application:
Start the backend server in development mode:
npm run dev
The server will be running at
http://localhost:3000.
Here are some of the available API endpoints:
POST /api/v1/auth/signup: Create a new user.POST /api/v1/auth/login: Log in a user.POST /api/v1/auth/logout: Log out a user.
POST /api/v1/imap: Add a new IMAP account.GET /api/v1/imap: Get all IMAP accounts for the user.GET /api/v1/imap/:id: Get a specific IMAP account.PUT /api/v1/imap/:id: Update an IMAP account.DELETE /api/v1/imap/:id: Delete an IMAP account.
-
GET /api/v1/emails: Get all emails for the logged-in user. This endpoint also supports search and filtering via query parameters:q: A string for full-text search across email subjects, bodies, and senders.folder: Filter emails by a specific folder (e.g.,INBOX).accountId: Filter emails by a specific IMAP account ID.
Examples:
GET /api/v1/emails?q=meetingGET /api/v1/emails?folder=INBOX&accountId=1GET /api/v1/emails?q=urgent&folder=Sent
MailGenie provides robust IMAP account management, allowing you to connect multiple email accounts to a single, unified inbox. Here’s how it works:
-
Adding an Account: When you add a new IMAP account, MailGenie securely stores your credentials and establishes a connection to the IMAP server. It then performs an initial synchronization by fetching all emails from the last 30 days.
-
Real-time Updates: After the initial sync, MailGenie uses the
IDLEcommand to listen for new emails in real-time. This ensures that your unified inbox is always up-to-date without constantly polling the server. -
Email Processing: As new emails arrive, they are processed and indexed in Elasticsearch, making them available for full-text search. The AI-powered categorization and smart reply features are also applied at this stage.
You can update your IMAP account settings at any time. When you modify your credentials, MailGenie will re-authenticate and re-establish the connection to ensure uninterrupted service.
Yes, it is possible to run multiple threads (or worker processes) to handle multiple IMAP accounts concurrently. In a Node.js environment, this can be achieved using worker threads or by forking child processes.
-
Improved Performance: Concurrent processing would allow MailGenie to fetch and synchronize emails from multiple accounts simultaneously, leading to faster updates and a more responsive user experience.
-
Enhanced Scalability: By isolating each IMAP connection in its own thread, the system can better handle a growing number of accounts without performance degradation.
-
Increased Complexity: Managing multiple threads adds complexity to the codebase, particularly concerning state management, error handling, and resource allocation.
-
Resource Consumption: Each thread consumes additional memory and CPU resources. A poorly managed multi-threaded system could lead to higher operational costs and potential stability issues.
While MailGenie currently processes IMAP accounts sequentially, a future update could introduce a multi-threaded approach to further enhance its performance and scalability.