2.1 KiB
2.1 KiB
Gmail Invoice Extractor
This application automatically scans Gmail for emails containing PDF attachments, checks if they contain your company's VAT number, and saves them to a designated folder.
Features
- 🔍 Scans Gmail for emails with PDF attachments
- 📄 Extracts text from PDF files using OCR
- 💾 Automatically saves valid invoices to a local folder
- 📝 Comprehensive logging
- 🐳 Docker support
Setup
1. Gmail API Setup
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Enable the Gmail API
- Create credentials (OAuth 2.0 Client ID)
- Download the credentials file and save it as
credentials.jsonin this directory
2. Configuration
- Update the VAT number patterns in
config.yamlto match your company's VAT numbers - Modify the Gmail search query if needed (default: emails with PDF attachments)
3. Running the Application
Option A: Direct Python execution
pip install -r requirements.txt
python main.py
Option B: Using Docker
docker build -t gmail-invoice-extractor .
docker run -v $(pwd)/invoices:/app/invoices -v $(pwd)/credentials.json:/app/credentials.json gmail-invoice-extractor
First Run
On the first run, the application will:
- Open a browser window for Gmail authentication
- Ask you to authorize the application
- Save the authentication token for future runs
Configuration
Edit config.yaml to customize:
- VAT number patterns for your company
- Gmail search query
- Maximum messages to process
- Save folder location
- Logging level
Logs
The application creates detailed logs in invoice_extractor.log and displays them in the console.
Security Notes
- Keep your
credentials.jsonandtoken.jsonfiles secure - Never commit these files to version control
- The application only requests read-only access to Gmail
Troubleshooting
- Authentication issues: Delete
token.jsonand run again to re-authenticate - No PDFs found: Check your Gmail search query in
config.yaml - VAT numbers not detected: Verify your VAT number patterns in
config.yaml