A local Python application that monitors your Gmail inbox and automatically sends replies to new emails.
- 🔍 Monitors Gmail inbox for new unread messages
- 📧 Automatically sends replies to incoming emails
- 🔐 Secure OAuth2 authentication with Gmail API
- 🚫 Prevents duplicate replies to the same message
- 📝 Marks processed messages as read
pip install -r requirements.txt- Go to the Google Cloud Console
- Create a new project or select an existing one
- Enable the Gmail API:
- Go to "APIs & Services" > "Library"
- Search for "Gmail API" and enable it
- Create OAuth 2.0 credentials:
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth 2.0 Client IDs"
- Choose "Desktop application"
- Download the credentials file
- Rename the downloaded file to
credentials.jsonand place it in this directory
python gmail_auto_reply.pyOn first run, you'll be prompted to authenticate with your Gmail account. A browser window will open for OAuth2 authorization.
- Authentication: Uses OAuth2 to securely access your Gmail account
- Monitoring: Checks for new unread messages every 30 seconds
- Processing: For each new email:
- Extracts sender, subject, and body
- Sends an auto-reply with "test\nyup its working"
- Marks the original message as read
- Prevents duplicate processing
To change the auto-reply content, edit the reply_text variable in the send_auto_reply method:
reply_text = "Your custom auto-reply message here"To change how often the system checks for new emails, modify the check_interval parameter in the run() method:
auto_reply.run(check_interval=60) # Check every 60 seconds- Credentials are stored locally in
token.json - Never commit
credentials.jsonortoken.jsonto version control - The application only requests necessary Gmail permissions
-
"credentials.json not found"
- Make sure you've downloaded and renamed the OAuth2 credentials file
-
Authentication errors
- Delete
token.jsonand re-authenticate - Ensure your Google Cloud project has Gmail API enabled
- Delete
-
Permission denied
- Check that your OAuth2 credentials have the correct scopes
- Verify the Gmail API is enabled in your Google Cloud project
This local setup can be extended to:
- Integrate with LLM APIs for intelligent responses
- Deploy to AWS Lambda for serverless operation
- Add more sophisticated email filtering and routing
- Implement conversation threading and context awareness
gmail_auto_reply.py- Main applicationrequirements.txt- Python dependenciescredentials.json- Gmail API credentials (you need to add this)token.json- OAuth2 tokens (generated automatically)