MailSage is a private, invite-only Gmail companion built with Next.js. It uses OpenAI to summarise individual email messages, identify potential action items and key links, and provide an AI-powered assistant for exploring inbox metadata.
Live Application (Invite-only): https://mailsage-desktop.vercel.app
Project Status: MailSage is an independently developed, limited-access internal tool currently available to its creator and a small group of approved test users. It is not a publicly-released email service. Access is managed through Google OAuth test-user approval, and Gmail permissions are read-only.
- Real Gmail Integration: Securely fetches live emails via the Gmail API (ReadOnly scope).
- AI Message Summaries: Generates summaries of individual email messages, highlighting potential action items and key links. Summaries are based on the extracted content of the selected message, rather than automatically retrieving and combining every message in a conversation thread.
- AI Inbox Assistant: Ask questions about senders, subjects and dates within the currently loaded inbox. The assistant can help identify and pin matching emails, but does not analyse the contents of email bodies.
- Smart Search: Instant, keyboard-driven search filtering.
- Persistent Pinning System: Pin important emails for quick access. Pinned message IDs are saved in browser localStorage under an account-specific key and persist across page refreshes and sign-in sessions.
- Keyboard Shortcuts: Navigate your inbox without touching the mouse.
- Appearance Toggle: Switches the appearance of selected interface controls, while the main application retains its dark-themed design.
- Persistent Hide Actions: Use the Archive or Delete icons to hide emails from the MailSage interface. Hidden message IDs are stored locally and remain hidden across refreshes and sign-in sessions. These actions do not modify, archive or delete emails in Gmail.
- Inbox Retrieval: Loads up to 50 messages from the user's Gmail Inbox. Search and date-range filters operate on this retrieved set rather than the user's entire mailbox.
MailSage also served as the initial source-code test environment for the MailSage Code Explainer, a reusable AI agent skill designed to help explain JavaScript code, describe application workflows and identify implementation defects. Later evaluations used synthetic JavaScript examples rather than personal Gmail data.
The experiment covers 26 recorded evaluations (Tests A–Z), progressing from exploratory comparisons to controlled, synthetic defect-discovery benchmarks. Frozen Benchmark V2 contains eight deliberately seeded defects; its reference implementation was checked with 55 automated JavaScript tests. In four final blind evaluations, configurations with and without Skill V3 identified all eight seeded defects. These small, high-performing samples did not establish an improvement in seeded-defect recall attributable to the skill.
This is a separate AI engineering and evaluation experiment, not a feature of the live MailSage email application.
- Experiment overview and methodology — objectives, setup, findings and limitations.
- Full evaluation report (Tests A–Z) — test history, methodology, scoring, evidence and conclusions.
- Evaluation tracker (Excel, .xlsx) — the downloadable workbook containing the recorded tests and supporting analysis.
- Seven CSV datasets — GitHub-readable tabular exports of the tracker data.
- Agent skill instructions — the reusable instructions used in the skill-assisted evaluations.
- Framework: Next.js 16.4.1 (App Router)
- Styling: Tailwind CSS
- Authentication: NextAuth.js 4.24.15 (Google Provider, JWT sessions)
- Email Rendering Security: DOMPurify for HTML content sanitisation.
- Local Persistence: Browser localStorage for account-specific pinned and hidden email preferences.
- AI: OpenAI API (
gpt-4o) - Animations: Framer Motion
- Icons: Lucide React
- Fonts: Google Fonts (Jua)
To run this project, you need to create a .env (or .env.local) file in the root directory with the following keys:
# Google Cloud Console -> APIs & Services -> Credentials
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
# OpenAI Platform -> API Keys
OPENAI_API_KEY=sk-your_openai_key
# NextAuth Configuration
# Generate a random string: `openssl rand -base64 32` in terminal
NEXTAUTH_SECRET=random_secure_string
# URL Configuration (Local Development)
NEXTAUTH_URL=http://localhost:3000Production deployment: When deploying your own instance to Vercel, configure NEXTAUTH_URL in your Vercel project's environment variables using your actual deployment domain (for example, https://your-app.vercel.app).
Keep NEXTAUTH_URL=http://localhost:3000 in your local .env.local file when running the application on your computer.
MailSage uses Google OAuth 2.0 for authentication and the Gmail API to retrieve emails.
To configure authentication for your own instance:
- Visit Google Cloud Console.
- Create a new project or select an existing one.
- Navigate to APIs & Services → Library and enable the Gmail API.
- Configure the Google OAuth consent screen.
- Select External if users will authenticate with personal Google accounts.
- Keep the application in Testing mode if it is intended for a limited group of users.
- Add the Google email addresses of your intended users under Test users.
- Request the
https://www.googleapis.com/auth/gmail.readonlyscope.
- Navigate to Clients (or Credentials, depending on the Google Cloud interface).
- Create an OAuth 2.0 Client ID and select Web application.
For local development:
http://localhost:3000
For a deployed instance (if a JavaScript origin is required):
https://your-app.vercel.app
For local development:
http://localhost:3000/api/auth/callback/google
For a deployed instance:
https://your-app.vercel.app/api/auth/callback/google
Important: Replace your-app.vercel.app with the domain assigned to your own deployment. If you use a custom domain, use that instead.
The redirect URI must match the callback URL configured for your application.
For MailSage's server-side NextAuth authentication flow, the authorised redirect URI is required. Authorised JavaScript origins may be unnecessary unless you also use browser-side Google OAuth functionality.
If your Google OAuth application remains in Testing mode, only Google accounts added to the application's test-user list can authorise access.
Approved testers may see Google's "Google hasn't verified this app" warning during authentication. This is expected for an unverified application in Testing mode.
MailSage requests read-only Gmail access and does not require permission to send, delete or modify emails.
# 1. Clone the repository
git clone https://github.com/boyluan/mailsage.git
# 2. Enter the project directory
cd mailsage
# 3. Install dependencies
npm install
# 4. Run the development server
npm run devOpen http://localhost:3000 in your browser.
| Shortcut | Action |
|---|---|
Cmd + K / Ctrl + K |
Open/Close AI Chat Assistant |
/ (Forward Slash) |
Focus Search Bar |
Esc |
Close open views or overlays; unfocus the search field without clearing the entered text |
↑ / ↓ |
Navigate Email List |
Enter |
Open Selected Email |
- Push your code to GitHub.
- Go to Vercel and "Add New Project".
- Import your
mailsagerepository. - Configure Environment Variables: In Vercel, navigate to Project Settings → Environment Variables and add the required credentials from your local
.env.localfile (GOOGLE_CLIENT_ID,GOOGLE_CLIENT_SECRET,OPENAI_API_KEYandNEXTAUTH_SECRET). ConfigureNEXTAUTH_URLfor your production deployment using its actual domain (e.g.,https://your-app.vercel.app), rather thanhttp://localhost:3000. Ensure the variables are assigned to the appropriate Vercel environment (Production or Preview). Preview deployments that require Google authentication must also use authentication settings appropriate to their own deployment URLs. - Click Deploy.
Post-Deployment Checklist:
- Copy your new Vercel domain (e.g.,
https://mailsage.vercel.app). - Go back to Google Cloud Console.
- Update Authorised redirect URIs in Google Cloud Console to include the full production callback URL (e.g.,
https://your-app.vercel.app/api/auth/callback/google), replacing the example domain with your actual production domain. - Update the
NEXTAUTH_URLvariable in Vercel settings if needed.
Vercel generates preview deployments for changes made on non-production branches, allowing updates to be tested before they are merged into main.
Google OAuth requires the application's redirect URI to match an authorised URI registered in Google Cloud Console.
For preview deployments, the callback URL follows this format:
https://your-preview-domain.vercel.app/api/auth/callback/google
To enable Google authentication in a preview deployment:
- Open the Vercel preview deployment and copy its exact domain.
- Navigate to Google Cloud Console → Google Auth Platform → Clients and select the OAuth client used by MailSage.
- Under Authorised redirect URIs, add the preview deployment's callback URL, including
/api/auth/callback/google. - Ensure the preview environment has the appropriate authentication environment variables configured, including a matching
NEXTAUTH_URLif explicitly set. - Save the changes and test Google sign-in using an approved test account.
Important: Preview deployment URLs may change between deployments. Because Google OAuth does not support wildcard redirect URIs, new preview URLs may require additional entries in Google Cloud Console.
During testing, I encountered Google's Error 400: redirect_uri_mismatch. Inspecting the error details revealed the exact callback URL being requested. Adding this URL to the authorised redirect URIs resolved the authentication issue and allowed testing to continue.
This release improved MailSage's email management controls, authentication handling, and HTML rendering security.
Changes:
- Updated Next.js and NextAuth dependencies.
- Implemented JWT-based session handling and server-side retrieval of Gmail access tokens.
- Added DOMPurify sanitisation for HTML email rendering.
- Introduced account-specific localStorage persistence for pinned and hidden email IDs.
- Preserved read-only Gmail behaviour for all local archive and delete actions.
Validation:
- Successful production build.
- Zero vulnerabilities reported by
npm audit --omit=dev. - Functional testing of authentication, pinning, hiding and persistence across browser refreshes and sign-in sessions.
- Verified that Gmail messages remained unchanged.
- Successfully tested the Vercel preview environment before merging and deploying to production.
Remaining consideration: Five high-severity vulnerabilities associated with the development-dependency chain were identified during the full npm audit and remain to be reviewed.
Development record: GitHub Pull Request #1 — Email actions, security and persistence
MailSage is a limited-access application developed as an internal tool and currently used by its creator and a small group of invited users.
- Inbox retrieval: The application retrieves up to 50 messages from Gmail's Inbox per request. Pagination is not currently implemented.
- Search and date filters: Results are limited to messages already retrieved by the application.
- AI summaries: Summaries are generated from individual email messages, not independently reconstructed conversation threads. The extracted text is limited to 6,000 characters per summary request.
- AI assistant: The assistant uses sender, subject and date metadata from currently loaded messages. It does not analyse full email bodies.
- Local Preference Storage: Pinned and hidden email preferences are stored in browser localStorage. They persist across refreshes and sign-in sessions on the same browser, but do not automatically synchronise between devices or browser profiles. Clearing browser storage can remove these preferences.
- MailSage-only Hide Actions: The Archive and Delete controls hide messages from MailSage's interface. They do not modify, archive or delete messages in Gmail. There is currently no dedicated in-app interface for restoring hidden messages.
- Appearance: The appearance toggle changes selected interface controls rather than providing a complete light theme.
- Never commit your
.envfile. It is included in.gitignoreby default to protect your API keys. - If you accidentally push a key, revoke it immediately in the Google/OpenAI dashboard.