An intelligent n8n workflow that automatically classifies, organizes, and prioritizes your Gmail emails using AI. This workflow runs daily to help you maintain a clean and organized inbox by categorizing emails into Important, Can Wait, or Spam categories.
- AI-Powered Classification: Uses Google Gemini to intelligently categorize emails
- Automatic Gmail Labeling: Applies appropriate labels based on priority
- Discord Notifications: Get notified about important emails instantly
- Scheduled Processing: Runs automatically every day at 8 AM
- Smart Summarization: Provides concise summaries of email content
- Schedule Trigger: Runs daily at 8 AM
- Fetch Emails: Retrieves recent Gmail messages
- AI Analysis: Google Gemini analyzes each email and classifies it as:
- Important: Actionable or high-priority (work, clients, deadlines, bills)
- Can Wait: Low-priority (newsletters, notifications, social media)
- Spam: Unwanted, promotional, or irrelevant content
- Auto-Labeling: Applies Gmail labels based on classification
- Notifications: Sends Discord notification for important emails
Before importing this workflow, you'll need:
- n8n instance (cloud or self-hosted)
- Gmail account with API access
- Google Gemini API key
- Discord webhook (optional, for notifications)
- Download the
Email Cleaner & Priority Sort AI Agent.jsonfile - In your n8n instance, go to Workflows
- Click Import from file or Import from clipboard
- Select the downloaded JSON file
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Gmail API
- Create OAuth2 credentials
- In n8n, create a new Gmail OAuth2 credential
- Follow the OAuth flow to authorize access
- Go to Google AI Studio
- Create a new API key
- In n8n, create a new Google Gemini (PaLM) API credential
- Enter your API key
- In your Discord server, go to Server Settings β Integrations
- Click Create Webhook
- Copy the webhook URL
- In n8n, create a new Discord Webhook credential
- Paste the webhook URL
Create these labels in your Gmail account:
- Important (or any custom name for high-priority emails)
- Can Wait (or any custom name for low-priority emails)
- The workflow will automatically use the Spam label
After creating labels, you'll need to update the label IDs in the workflow:
- Go to Gmail
- Get label IDs from the URL when viewing each label
- Update the
labelIdsin the respective Gmail nodes
- Default: Daily at 8 AM
- To change: Edit the Schedule Trigger node
- Options: Hourly, daily, weekly, or custom cron expression
- Edit the Basic LLM Chain node to modify classification criteria
- Adjust categories or add new classification rules
- Customize the summary format
You can modify the Gmail node to filter emails by:
- Date range (only process recent emails)
- Sender domains
- Subject keywords
- Unread status
The default categories are:
- Important: Work, clients, deadlines, bills
- Can Wait: Newsletters, notifications, social media
- Spam: Unwanted, promotional content
Modify the AI prompt to add custom categories or change classification logic.
- Discord: Sends summary of important emails
- Email: Could be extended to send email notifications
- Slack: Could be adapted for Slack notifications
- No credentials are stored in the workflow file - only references
- Emails are processed locally through your n8n instance
- AI processing uses Google Gemini API (check their privacy policy)
- OAuth tokens are securely managed by n8n
-
"Failed to parse cleaned Gemini response"
- The AI response format might be inconsistent
- Check the Code node for JSON parsing errors
- Consider adding more robust error handling
-
Gmail API Rate Limits
- Reduce the frequency of the schedule trigger
- Add delays between API calls
- Implement exponential backoff
-
Label IDs Not Working
- Ensure Gmail labels exist
- Update label IDs in the workflow
- Check Gmail API permissions
-
Discord Notifications Not Sending
- Verify webhook URL is correct
- Check Discord channel permissions
- Test webhook independently
- Enable debug mode in n8n
- Run the workflow manually
- Check execution logs for detailed error messages
- Test individual nodes to isolate issues
- Sentiment Analysis: Add emotion detection to emails
- Auto-Reply: Generate AI responses for certain email types
- Calendar Integration: Create calendar events from meeting emails
- CRM Integration: Log important emails to your CRM system
- Multi-Language Support: Handle emails in different languages
- Learning Mode: Train the AI on your email patterns
- Batch Processing: Handle large volumes of emails efficiently
- Custom Webhooks: Trigger actions based on email content
- Integration Hub: Connect with other automation tools
Feel free to:
- Report bugs or issues
- Suggest improvements
- Submit pull requests
- Share your customizations
This workflow is open source and available under the MIT License.
- Built with n8n - Fair-code workflow automation
- Powered by Google Gemini for AI classification
- Inspired by the need for better email management
If you need help:
- Check the n8n community forum
- Read the n8n documentation
- Open an issue in this repository
Happy email organizing! π§β¨