Invoices from email → one payment table
If invoices arrive by email, the bottleneck is not reading them but collecting them into one list. Here is a workflow that does it in one pass.
The workflow
- Collect — a script scans the mailbox for messages with attachments and saves PDFs to a folder.
- Filter — keep files whose name or subject matches invoice patterns (
invoice,receipt,счёт). - Extract — pull the amount, date and vendor from the PDF text.
- Reconcile — write everything into one Excel sheet and match against bank payments.
Step 1–2: collect only invoice emails
status, data = imap.search(None, '(SINCE 01-Sep-2026 SUBJECT "invoice")')
# for Outlook / Yandex also try: SUBJECT "receipt", SUBJECT "счёт"
Server-side search is much faster than downloading every message and filtering locally.
Step 3: amount extraction
PDFs are not text files — use pdfplumber or pypdf to get text, then a strict regex:
import re
amount = re.search(r"(?:total|amount due|итого)[^0-9]{0,20}([0-9][0-9 .,]*)", text, re.I)
What to put in the table
| Column | Source |
|---|---|
| received_at | email date |
| vendor | sender domain / PDF header |
| invoice_no | PDF text regex |
| amount, currency | PDF text regex |
| file | saved attachment path |
| status | paid / unmatched / review |
Why not a full accounting system
Accounting suites assume invoices are already in a structured feed. If suppliers send PDFs to a mailbox, a small script bridges the gap in an afternoon — and keeps working every month.
Need the collector without writing code? The $3 script saves attachments and writes the email table; the PDF amount step is usually a 20-line addition.
FAQ
Can this replace accounting software?
No. It builds the input table. Reconciliation and reporting still belong to your accounting system.
What about scanned PDFs?
Scanned invoices need OCR (Tesseract). Add OCR only if most of your suppliers send scans — it slows the pipeline significantly.
Is it safe to process invoices locally?
Yes, and it is usually safer than uploading financial documents to random online converters.
Related guides
- Extract attachmentsStep 1 of this workflow in detail.
- For accountantsA version of this workflow for bookkeeping teams.