Quick overview
This workflow ingests e-invoices via IMAP email or an n8n upload form, extracts and parses XRechnung/ZUGFeRD/Factur-X/Peppol XML, runs plausibility checks, deduplicates and stores results in an n8n Data Table, and emails accounting for review or forwards clean invoices, with an optional local Ollama AI fallback for plain PDFs.
How it works
- Triggers when a new email arrives via IMAP or when a user uploads PDF/XML files through an n8n Form.
- Splits incoming messages into one item per PDF/XML attachment and extracts embedded e-invoice XML from ZUGFeRD/Factur-X PDFs when present.
- Parses CII and UBL e-invoice XML into a normalized invoice structure, generates a readable PDF view for XML-only invoices, and runs plausibility checks (totals, VAT, due date, IBAN and VAT ID formats, and missing mandatory fields).
- If no e-invoice XML is found in a PDF, extracts the PDF text and uses a local Ollama chat model to extract key invoice fields, marking the result for manual review.
- Checks for duplicates using an n8n Data Table key (seller + invoice number) and either flags duplicates or inserts new invoices into the e_invoices table.
- Emails accounting when an invoice is a duplicate or fails checks, attaching the original file and any generated readable PDF.
- For invoices that pass checks, optionally forwards the appropriate attachment (readable PDF when generated, otherwise the original file) to a configured bookkeeping inbox.
- On manual run, exports the previous month’s invoices from the Data Table to a semicolon-delimited CSV and emails it to a tax advisor.
Setup
- Execute the “Run once: create table” path to create the n8n Data Table named e_invoices with the required columns.
- Add IMAP credentials for the Email Read node and SMTP credentials for the Email Send nodes (or replace them with Gmail/Microsoft Outlook email nodes if needed).
- Update the Settings values for accountingEmail, senderEmail, and optionally accountingInbox, and set the target tax advisor email address in the monthly export email step.
- If you want the plain-PDF fallback, configure the Ollama connection and choose an available model in the Ollama chat model step.
- If using the upload option, copy the Form URL from n8n and share it with users who need to submit invoices.