Automatically collects invoices from a personal Outlook/Hotmail inbox, classifies them with AI, stores them in OneDrive organized by year/month, and generates a monthly Excel summary.
Fully automatic. Once set up, no manual intervention is needed.
- Every N minutes: polls the Outlook inbox via Microsoft Graph API
- Filters emails by subject keywords and an optional sender whitelist
- Uses an AI classifier (Claude) to confirm attachments are actual invoices
- Downloads PDF/image attachments
- Uploads them to OneDrive under
<folder>/YYYY/MM/ - On the 1st of each month: generates an Excel summary and uploads it to OneDrive
- Docker + Docker Compose installed on your server or NAS
- A personal Outlook/Hotmail account (the account owner logs in once via browser)
- An Azure App Registration (free, takes 5 minutes — see below)
- An Anthropic API key (for the invoice classifier)
- Go to portal.azure.com (sign in with any Microsoft account)
- Search "App registrations" -> click New registration
- Fill in:
- Name:
invoice-bot - Supported account types: select "Personal Microsoft accounts only"
- Redirect URI: leave blank
- Name:
- Click Register
- Copy the Application (client) ID — you will need it in
.env
In your app -> API permissions -> Add a permission -> Microsoft Graph -> Delegated permissions, add:
| Permission | Why |
|---|---|
Mail.Read |
Read inbox to find invoices |
Files.ReadWrite |
Upload invoices to OneDrive |
offline_access |
Keep the session alive permanently |
Click Grant admin consent (or it will be granted on first login).
Authentication -> scroll to Advanced settings -> toggle "Allow public client flows" -> Yes -> Save
Secrets (.env):
cp .env.example .envEdit .env and fill in your API keys:
AZURE_CLIENT_ID=paste-your-azure-client-id-here
ANTHROPIC_API_KEY=paste-your-anthropic-api-key-here
Settings (config.yaml):
cp config.example.yaml config.yamlEdit config.yaml and fill in:
onedrive:
folder_name: "Invoices" # Root folder created automatically in OneDrive
invoices:
whitelisted_senders: # Optional — omit to scan all emails
- "factures@supplier1.fr"
- "billing@supplier2.com"See config.example.yaml for all available options.
# Clone or copy the project to your server
cd invoice-bot
# Build the Docker image
docker compose build
# Start the container
docker compose up -dThe account owner needs to log in once. Run:
docker exec -it invoice-bot python src/auth_setup.pyYou will see something like:
============================================================
ACTION REQUIRED - Microsoft Account Login
============================================================
To sign in, use a web browser to open https://microsoft.com/devicelogin
and enter the code ABCD-EFGH to authenticate.
============================================================
- Open that URL on any browser (phone, tablet, laptop)
- Enter the code shown
- Sign in with the Outlook/Hotmail account you want to monitor
- Done — the token is saved to
data/ms_token_cache.json
The bot will silently refresh the token automatically. You only need to repeat this step if the refresh token expires (after 90 days of zero activity).
# View live logs
docker compose logs -f
# Stop the bot
docker compose down
# Restart after a config change
docker compose restart
# Rebuild after code changes
docker compose build && docker compose up -dEdit config.yaml, add the supplier's email to whitelisted_senders, then restart:
docker compose restartNo rebuild needed — config is read on startup.
Invoices/
├── 2026/
│ ├── 01/
│ │ └── 2026-01-15_supplier1_invoice-123.pdf
│ └── 02/
│ ├── 2026-02-03_supplier2_receipt.pdf
│ └── 2026-02-19_supplier1_facture-456.pdf
└── 2027/
└── ...
invoice-bot/
├── docker-compose.yml
├── Dockerfile
├── requirements.txt
├── .env # Your secrets (gitignored)
├── .env.example # Secrets template
├── config.yaml # Your settings (gitignored)
├── config.example.yaml # Settings template
├── LICENSE
├── .gitignore
├── data/ # Auto-created, mounted as volume
│ ├── invoices.db # SQLite database
│ └── ms_token_cache.json # Microsoft auth token
└── src/
├── main.py # Entry point + scheduler
├── auth_setup.py # One-time Microsoft login
├── poller.py # Graph API inbox polling
├── classifier.py # AI invoice classifier (Claude)
├── pipeline.py # Processing orchestration
├── onedrive_uploader.py # OneDrive upload via Graph API
├── excel_exporter.py # Monthly Excel summary builder
├── db.py # SQLite operations
└── utils.py # Shared config & logging
MIT — see LICENSE.