This guide walks you through setting up the Email Management Utility step by step.
- Python 3.7 or higher
- pip (Python package installer)
- A Gmail account and/or Outlook/Microsoft 365 account
pip install -r requirements.txtExpected output:
Successfully installed google-auth-2.25.2 google-auth-oauthlib-1.2.0 ...
-
Go to Google Cloud Console
- Visit: https://console.cloud.google.com
- Sign in with your Google account
-
Create New Project
- Click the project dropdown at the top
- Click "New Project"
- Project name: "Email Manager" (or your choice)
- Click "Create"
- Wait for project creation (takes a few seconds)
-
Select Your Project
- Use the project dropdown to select your new project
-
Navigate to APIs
- Click hamburger menu (☰) → "APIs & Services" → "Library"
-
Enable Gmail API
- Search for "Gmail API"
- Click on it
- Click "Enable"
- Wait for activation
-
Enable Google Calendar API
- Click "< Go back" or search again
- Search for "Google Calendar API"
- Click on it
- Click "Enable"
-
Go to OAuth Consent
- Click hamburger menu → "APIs & Services" → "OAuth consent screen"
-
Choose User Type
- Select "External"
- Click "Create"
-
Fill App Information
- App name: "Email Manager"
- User support email: Your email
- Developer contact: Your email
- Click "Save and Continue"
-
Scopes (Step 2)
- Click "Save and Continue" (we'll add scopes in credentials)
-
Test Users (Step 3)
- Click "Add Users"
- Enter your Gmail address
- Click "Add"
- Click "Save and Continue"
-
Summary (Step 4)
- Review and click "Back to Dashboard"
-
Go to Credentials
- Click hamburger menu → "APIs & Services" → "Credentials"
-
Create Credentials
- Click "Create Credentials" at top
- Select "OAuth client ID"
-
Configure OAuth Client
- Application type: "Desktop app"
- Name: "Email Manager Desktop"
- Click "Create"
-
Download Credentials
- A popup appears with your Client ID and Secret
- Click "Download JSON"
- Save the file
-
Rename Downloaded File
- Rename the downloaded file to:
gmail_credentials.json - Move it to your email-manager directory
- Rename the downloaded file to:
Your gmail_credentials.json should look like:
{
"installed": {
"client_id": "123456789-abcdefg.apps.googleusercontent.com",
"project_id": "email-manager-xxxxx",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_secret": "GOCSPX-xxxxxxxxxxxxxxxxx",
"redirect_uris": ["http://localhost"]
}
}python email_manager.py --provider gmail --setup-onlyWhat happens:
- Browser opens automatically
- Sign in to your Google account
- You'll see "Google hasn't verified this app" warning
- Click "Advanced"
- Click "Go to Email Manager (unsafe)"
- This is normal for personal projects
- Grant permissions:
- ✓ Read, compose, send, and permanently delete all your email
- ✓ See, edit, share, and permanently delete calendars
- Click "Continue"
- Browser shows "The authentication flow has completed"
- Return to terminal - should show "Gmail authentication successful"
Files created:
gmail_token.pickle- Your saved authentication token
-
Go to Azure Portal
- Visit: https://portal.azure.com
- Sign in with your Microsoft account
-
Navigate to App Registrations
- Search bar at top: Type "App registrations"
- Click "App registrations" service
-
Create New Registration
- Click "+ New registration"
-
Fill Registration Details
- Name: "Email Manager"
- Supported account types:
- Select "Accounts in any organizational directory and personal Microsoft accounts"
- Redirect URI: Leave blank for now
- Click "Register"
-
Note Your Client ID
- After creation, you'll see the Overview page
- Copy the "Application (client) ID"
- Example:
12345678-1234-1234-1234-123456789abc - Save this - you'll need it!
-
Go to Authentication
- In left sidebar: Click "Authentication"
-
Add Platform
- Click "Add a platform"
- Select "Mobile and desktop applications"
-
Configure Redirect URIs
- Check the box for
http://localhost - Click "Configure"
- Check the box for
-
Advanced Settings (on Authentication page)
- Allow public client flows: "Yes"
- Click "Save" at top
-
Go to API Permissions
- In left sidebar: Click "API permissions"
-
Add Permission - Mail
- Click "+ Add a permission"
- Click "Microsoft Graph"
- Click "Delegated permissions"
- Search for "Mail"
- Expand "Mail" and check:
- ✓ Mail.ReadWrite
- Click "Add permissions"
-
Add Permission - Calendar
- Click "+ Add a permission" again
- Click "Microsoft Graph"
- Click "Delegated permissions"
- Search for "Calendar"
- Expand "Calendars" and check:
- ✓ Calendars.ReadWrite
- Click "Add permissions"
-
Grant Admin Consent (if prompted)
- If you see a warning banner
- Click "Grant admin consent for [your organization]"
- Click "Yes" to confirm
Final permissions list should show:
- Microsoft Graph (2):
- Calendars.ReadWrite (Delegated)
- Mail.ReadWrite (Delegated)
-
Create outlook_credentials.json
# Copy the template cp outlook_credentials.json.template outlook_credentials.json -
Edit the file
- Open
outlook_credentials.json - Replace
YOUR_AZURE_AD_CLIENT_ID_HEREwith your actual Client ID - Save the file
- Open
Example outlook_credentials.json:
{
"client_id": "12345678-1234-1234-1234-123456789abc",
"authority": "https://login.microsoftonline.com/common"
}python email_manager.py --provider outlook --setup-onlyWhat happens:
- Browser opens automatically
- Sign in to your Microsoft account
- Grant permissions:
- ✓ Read and write access to your mail
- ✓ Read and write access to your calendars
- Click "Accept"
- Browser may show "Authentication complete, you can close this window"
- Return to terminal - should show "Outlook authentication successful"
# Test both providers
python email_manager.py --setup-onlyExpected output:
INFO - Setting up Gmail handler...
INFO - Authenticated as: your.email@gmail.com
INFO - Gmail authentication successful
INFO - Setting up Outlook handler...
INFO - Authenticated as: your.email@outlook.com
INFO - Outlook authentication successful
INFO - Setup complete. Run without --setup-only to process emails.
# Safe test - no emails will be modified
python email_manager.pyThis will show what emails would be processed without actually changing anything.
Solution:
- Make sure you downloaded the OAuth credentials from Google Cloud Console
- Rename the file to exactly
gmail_credentials.json - Place it in the same directory as the Python scripts
Solution:
- This is normal for personal projects
- Click "Advanced" → "Go to Email Manager (unsafe)"
- Your app is safe - Google just hasn't reviewed it because it's personal
Solution:
- Make sure you enabled both Gmail API and Google Calendar API
- Check that OAuth consent screen is configured
- Verify you added yourself as a test user
Solution:
- Copy the template:
cp outlook_credentials.json.template outlook_credentials.json - Edit the file and add your Client ID from Azure Portal
Solution:
- Verify redirect URI
http://localhostis added in Authentication settings - Check that "Allow public client flows" is enabled
- Ensure Mail.ReadWrite and Calendars.ReadWrite permissions are granted
Solution:
- Delete the token files:
rm gmail_token.pickle
- Re-run authentication:
python email_manager.py --setup-only
Once authentication is working:
-
Test in dry-run mode:
python email_manager.py
-
Review the logs:
- Check
email_manager.logto see what would be processed
- Check
-
If results look good, run live mode:
# Explicit authentication step (recommended before live runs) python email_manager.py --setup-only python email_manager.py --live -
Set up automation:
- See README.md for cron (Linux/Mac) or Task Scheduler (Windows) setup
🔐 Keep These Files Secret:
gmail_credentials.jsonoutlook_credentials.jsongmail_token.pickle
Never share these files or commit them to git!
🔒 Revoke Access Anytime:
- Gmail: https://myaccount.google.com/permissions
- Outlook: https://account.microsoft.com/privacy/app-access
Check the main README.md for:
- Usage examples
- Customization options
- Scheduling setup
- Troubleshooting guide