◈ Mail → Excel

Invoices from email → one payment table

By the Mail → Excel team · Updated 2026-10-18

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

  1. Collect — a script scans the mailbox for messages with attachments and saves PDFs to a folder.
  2. Filter — keep files whose name or subject matches invoice patterns (invoice, receipt, счёт).
  3. Extract — pull the amount, date and vendor from the PDF text.
  4. 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)
A regex works for 80% of invoices. For the rest, keep a “needs manual review” flag — do not silently drop rows.

What to put in the table

ColumnSource
received_atemail date
vendorsender domain / PDF header
invoice_noPDF text regex
amount, currencyPDF text regex
filesaved attachment path
statuspaid / 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