An intelligent email prioritization system that automatically organizes your Gmail emails using AI classification. The system identifies emails that need replies and business opportunities, then organizes them into dedicated folders for better email management.
- π€ AI-Powered Classification: Uses NVIDIA's LLM API to intelligently classify emails
- π Automatic Organization: Creates and organizes emails into
AI-Priority/Needs Reply
andAI-Priority/Business
folders - β° Automated Processing: Runs on a configurable schedule (every 15 minutes recommended)
- π Secure: Uses Gmail app-specific passwords and secure API keys
- β‘ Optimized Performance: Processes only recent emails with timeout protection
- π Detailed Logging: Comprehensive logging for monitoring and debugging
- π Vercel Ready: Designed for easy deployment on Vercel with cron jobs
Emails that require your attention and response:
- Direct questions or requests for information
- Meeting invitations requiring RSVP
- Customer inquiries or support requests
- Personal messages from contacts
- Action items or tasks assigned to you
Emails with potential money-making opportunities:
- Job offers and recruitment messages
- Partnership and collaboration proposals
- Investment opportunities
- Sales leads and business inquiries
- Speaking engagement invitations
- Consulting requests
- Monetization opportunities
- Frontend/Backend: Next.js 15 with TypeScript
- Email Processing: IMAP integration with Gmail
- AI Classification: NVIDIA LLM API (Llama-3.1-nemotron-ultra-253b-v1)
- Deployment: Vercel with cron jobs
- Styling: Tailwind CSS
Before setting up the system, you'll need:
- Gmail Account with 2FA enabled
- NVIDIA Developer Account for LLM API access
- Vercel Account for deployment
- Node.js 18+ for local development
- Go to Google Account Security
- Enable 2-Step Verification if not already enabled
- Go to Google App Passwords
- Select "Mail" and your device
- Copy the generated 16-character password
- Save this password securely - you'll need it for
GMAIL_APP_PASSWORD
- Visit NVIDIA Developer Portal
- Create an account or sign in
- Navigate to the API section
- Generate an API key for LLM access
- Save the API key - you'll need it for
NVIDIA_API_KEY
git clone <your-repo-url>
cd email-prioritizer
npm install
Create a .env.local
file in the root directory:
# Gmail Configuration
GMAIL_USER=your.email@gmail.com
GMAIL_APP_PASSWORD=your-16-character-app-password
# NVIDIA API Configuration
NVIDIA_API_KEY=your-nvidia-api-key
# Cron Security (generate a random string)
CRON_SECRET=your-random-secret-string
npm run dev
The application will be available at http://localhost:3000
curl http://localhost:3000/api/test-connection
curl -X GET "http://localhost:3000/api/cron/process-emails?minutes=60" \
-H "Authorization: Bearer your-random-secret-string"
npm install -g vercel
vercel login
vercel --prod
vercel env add GMAIL_USER
vercel env add GMAIL_APP_PASSWORD
vercel env add NVIDIA_API_KEY
vercel env add CRON_SECRET
vercel --prod
- Go to Vercel Dashboard
- Select your project
- Navigate to Settings β Security
- Disable Password Protection
- Save changes
The system includes a built-in Vercel cron job configuration in vercel.json
that runs daily at 9 AM UTC. However, for more frequent processing, we recommend using an external cron service.
- Create account at Val.town
- Create a new val with this code:
export default async function emailProcessor() {
const response = await fetch("https://your-vercel-app.vercel.app/api/cron/process-emails", {
method: "GET",
headers: {
"Authorization": "Bearer your-cron-secret"
}
});
const result = await response.json();
console.log("Email processing result:", result);
return result;
}
- Set up cron schedule:
*/15 * * * *
(every 15 minutes)
Create .github/workflows/email-cron.yml
:
name: Email Processing Cron
on:
schedule:
- cron: '*/15 * * * *' # Every 15 minutes
workflow_dispatch:
jobs:
process-emails:
runs-on: ubuntu-latest
steps:
- name: Process Emails
run: |
curl -X GET "${{ secrets.VERCEL_URL }}/api/cron/process-emails" \
-H "Authorization: Bearer ${{ secrets.CRON_SECRET }}"
GET /api/cron/process-emails?minutes=16
Authorization: Bearer your-cron-secret
Parameters:
minutes
(optional): Lookback window in minutes (default: 16)
Response:
{
"success": true,
"timestamp": "2024-01-01T12:00:00.000Z",
"duration": "15.2s",
"lookbackMinutes": 16,
"result": {
"totalEmails": 25,
"processedEmails": 25,
"needsReplyCount": 3,
"businessCount": 2,
"errorCount": 0,
"timeoutReached": false,
"remainingEmails": 0
}
}
GET /api/cron/process-emails-chunk?chunk=10&minutes=16
Authorization: Bearer your-cron-secret
GET /api/health
GET /api/test-connection
- Default: 16 minutes (perfect for 15-minute cron jobs)
- Configurable: Use
?minutes=X
parameter - Overlap: 1-minute buffer ensures no emails are missed
- Timeout Protection: 45-second processing limit
- Batch Processing: Processes emails in batches of 3-10
- Rate Limiting: Built-in delays to respect API limits
The system creates these Gmail folders automatically:
π AI-Priority/
βββ π Needs Reply/
βββ π Business/
Edit src/lib/llm-service.ts
to customize the classification prompt:
const prompt = `
Analyze this email and classify it based on your custom criteria:
Subject: ${email.subject}
From: ${email.from}
To: ${email.to}
Date: ${email.date}
// Add your custom classification logic here
`;
- Update the
EmailClassification
interface insrc/lib/email-service.ts
- Modify the classification logic in
src/lib/llm-service.ts
- Update folder creation in
src/lib/email-service.ts
Update vercel.json
for different Vercel cron schedules:
{
"crons": [{
"path": "/api/cron/process-emails",
"schedule": "0 */6 * * *" // Every 6 hours
}]
}
- Verify 2FA is enabled on your Google account
- Ensure app-specific password is correct (16 characters, no spaces)
- Check that IMAP is enabled in Gmail settings
- Verify your API key is valid and active
- Check your API usage limits
- Ensure you have access to the Llama model
- Reduce the processing window (
?minutes=5
) - Use the chunked endpoint for large email volumes
- Check Vercel function logs for specific errors
- Verify the time window is appropriate
- Check Gmail folder permissions
- Ensure emails exist in the specified timeframe
Enable detailed logging by checking Vercel function logs:
- Go to Vercel Dashboard
- Select your project
- Navigate to Functions tab
- Click on recent invocations to see logs
- Processing Time: Should be under 45 seconds
- Email Volume: Typical range 5-50 emails per 15-minute window
- Classification Accuracy: Monitor false positives/negatives
- Error Rate: Should be near 0%
The system provides comprehensive logging:
- Email fetching and filtering
- AI classification results
- Folder organization status
- Performance metrics
- Error details
We welcome contributions! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
- Follow TypeScript best practices
- Add proper error handling
- Include comprehensive logging
- Test with various email types
- Update documentation
This project is licensed under the MIT License - see the LICENSE file for details.
- NVIDIA for providing the LLM API
- Vercel for hosting and cron job infrastructure
- Gmail IMAP for email access
- Next.js for the application framework
If you encounter issues:
- Check the Troubleshooting section
- Review Vercel function logs
- Open an issue on GitHub
- Join our community discussions
Happy Email Organizing! π§β¨
Made with β€οΈ for better email management