Gmail uses the same OAuth credentials as Google Calendar. If you’ve already set up Google Calendar, you just need to enable the Gmail API and configure filtering preferences.
What Gmail Integration Enables
With Gmail configured, Morning Brain Starter can:- Display recent email messages in your morning briefing
- Filter emails by label (e.g., INBOX, specific labels)
- Limit the number of messages shown
- Filter messages by date range (e.g., last 7 days)
Prerequisites
- Google Calendar integration already configured (see Google Calendar Setup)
- Gmail API enabled in your Google Cloud project
- OAuth token with Gmail scope (generated by
setup_oauth.py)
Step 1: Enable Gmail API
Navigate to Google Cloud Console
Go to Google Cloud Console and select your Morning Brain Starter project.
If you already ran
setup_oauth.py, you may need to regenerate your token to include the Gmail scope. See Step 2 below.Step 2: Verify OAuth Token Has Gmail Scope
The OAuth token generated bysetup_oauth.py includes Gmail scope by default. However, if you generated your token before enabling the Gmail API, you’ll need to regenerate it.
Check if regeneration is needed
If you see errors related to Gmail permissions when running the morning routine, regenerate your token:
The
setup_oauth.py script requests all Google scopes in a single authorization flow:- Calendar (read and edit)
- Gmail (read only)
- Google Docs (read only)
- Google Meet (manage settings)
Step 3: Configure Gmail Settings
Customize Gmail integration behavior by editingconfig/email.yaml.
Configuration Reference
config/email.yaml
Location:config/email.yaml
Gmail label to filter messages.System labels:
INBOX- Main inboxSENT- Sent messagesDRAFT- Draft messagesSPAM- Spam folderTRASH- Trash folderIMPORTANT- Important messagesSTARRED- Starred messages
- Use the exact label name as it appears in Gmail
- For nested labels, use slash:
Work/Urgent
Maximum number of messages to retrieve.Purpose: Limits the number of messages shown in your morning briefing to avoid overwhelming output.Recommendation: 10-20 messages is usually sufficient for morning context.Example:
Number of days to look back when filtering messages.Purpose: Only show recent messages relevant to your current work.Recommendation: 3-7 days for active projects, 1-2 days for high-volume inboxes.Example:
Example Configurations
High-Volume Inbox
For busy inboxes, show only recent important messages:Work Email
Focus on work-related messages from the past week:Minimal Setup
Use defaults for standard inbox monitoring:OAuth Scopes Used
Gmail integration uses these OAuth scopes (requested bysetup_oauth.py):
Read-only access: Morning Brain Starter only reads your emails. It cannot send, delete, or modify messages.
Testing Your Configuration
After configuring Gmail:Verify token has Gmail scope
Run the morning routine:If you see a permission error, regenerate your token:
Check for email section
Look for an email section in the morning output. You should see:
- Subject lines of recent messages
- Sender information
- Date/time received
- Preview snippets
Troubleshooting
No emails appear in morning routine
No emails appear in morning routine
Possible causes:
- Gmail API not enabled
- OAuth token doesn’t include Gmail scope
- No messages match the filter criteria
- Verify Gmail API is enabled in Google Cloud Console
- Regenerate token:
.venv/bin/python scripts/setup_oauth.py --regenerate - Check
config/email.yamlfilters (label, days_back) - Verify messages exist matching your criteria in Gmail
Error: 'Insufficient Permission' or 'Access Not Granted'
Error: 'Insufficient Permission' or 'Access Not Granted'
Your OAuth token doesn’t have Gmail scope.Solution:
Regenerate the token with Gmail scope:Make sure to authorize Gmail access when the browser opens.
Wrong emails are shown
Wrong emails are shown
The label filter isn’t working as expected.Solution:
- Verify the label name in
config/email.yamlmatches exactly (case-sensitive) - For nested labels, use slash separator:
Parent/Child - For system labels, use uppercase:
INBOX,SENT,STARRED
Too many emails displayed
Too many emails displayed
Reduce the number of messages shown.Solution:
Edit
config/email.yaml:Error: 'Label not found'
Error: 'Label not found'
The label specified in
config/email.yaml doesn’t exist in your Gmail.Solution:- Open Gmail and verify the label exists
- Check spelling and capitalization in
config/email.yaml - Use
INBOXif unsure
Disabling Gmail Integration
Gmail integration is automatically disabled if:- Gmail API is not enabled in your Google Cloud project
- Your OAuth token doesn’t include the Gmail scope
- You leave
config/email.yamlwith default/empty settings
- Comment out or remove the Gmail scope when regenerating tokens (edit
scripts/setup_oauth.py) - Or simply don’t enable the Gmail API in Google Cloud Console
Privacy and Security
Token storage: Your
GOOGLE_REFRESH_TOKEN is stored in resources/secrets/.env, which is excluded from version control by default. Keep this file secure.Next Steps
Client Configuration
Map calendar events to clients
Asana Integration
Optional: Add task management
Usage Guide
Learn how to run morning routine
Google Calendar Setup
Review Google Calendar configuration