<!--
  Translated by the docs agent from content-src/es/integrations/conexiones-facturas/05-procedimiento-completo-la-plantilla-facturas-por-correo.md
  (source_hash fc63eaec3373). If that Spanish source_hash changes, re-check this translation.
-->

**Requirements:** Admin or Editor role; an "Email (read)" connection to the billing mailbox (section 4), an invoice-extraction connection (an identifier support gives you if you don't see it in your panel) and, to save the data, Google Sheets + Drive or Excel + OneDrive connected with at least one write-permission resource registered (section 3) — plus the destination sheet/workbook and folder already created: the template never creates the document for you, it only writes to one that already exists.

There are two variants of the template: **Google** (a Sheets spreadsheet + a Drive folder) and **Microsoft** (an Excel workbook + a OneDrive folder). Under the hood, both use the **"Repeat for each item"** step (Manual 55, section 3.7) to process each email separately — it's the same piece any other flow with repetition uses, applied to this specific case.

1. In **Flows**, press **"New flow"** → **"From a template"** and choose your variant (Google or Microsoft).
2. Name it, choose the **agent** that runs it, and fill in the connection and destination identifiers it asks for (section 2 of this same procedure, below).
3. Press **"Create flow"**.

## 5.1 How to get the identifiers the form asks for

All of them are text you copy from a screen or a URL — there's never any "coding" involved:

- **Connection identifiers** (email, Sheets/Excel, Drive/OneDrive, invoice extraction): in **Integrations**, open the connection and copy its identifier — a long code like `a1b2c3d4-…`. The "invoice extraction" connection's is usually a single, internal-use one; ask support for it if you don't see it in your panel.
- **Google spreadsheet ID**: open it in your browser — it's the long chunk of the URL between `/d/` and `/edit`.
- **Google Drive folder ID**: open it in your browser — it's the chunk after `/folders/` in the URL.
- **Tab name** (Sheets) or **sheet name** (Excel): the name of the tab where you want rows added — you can leave the template's default ("Invoices") if your document has a tab with that name, or type your own.
- **Excel workbook ID and OneDrive drive/folder ID**: if you don't know how to get these from the OneDrive URL, ask support or check the Microsoft Graph documentation — there isn't a visual assistant to copy them with one click today.

## 5.2 What the flow does, step by step

1. **Look for new invoices**: every scheduled trigger (twice a day, by default — adjustable like any flow) checks the mailbox for new messages.
2. **Repeat for each email** (Manual 55, section 3.7) — inside, for each message:
  1. Reads the full message and downloads its first attachment.
  2. Extracts the invoice's data (supplier, number, date, amount, currency) using an AI model over the **attachment's text only**, never the full email.
  3. Validates that data **deterministically** (no AI): date format, positive amount, date not excessively in the future — the LLM never decides alone whether an invoice is valid.
  4. Saves the row to your sheet/Excel, uploads the PDF to your folder, and marks the email as processed — **automatically** if everything checks out and confidence is high, or **awaiting your approval** (Manual 55, section 2.6) if validation fails or confidence is low, with the PDF in view so you can review it before it's saved.
3. **Failure alert**: if reading a specific message fails (mailbox down, unreadable attachment…), an internal alert is logged — it never silently keeps retrying that same message without anyone finding out (Manual 55, section 3.9).

> **Note — It may ask you to approve more than once for the same email**
>
> The final step saves the row, uploads the PDF and marks the email as processed in a single block of 3 actions — so if that email needs your approval, it's normal to be asked once per remaining action. Keep approving until the item reaches "Done": it's not an error or a duplicate approval (Manual 55, section 2.6).

Run twice on the same day, it doesn't duplicate anything: every email is identified by its message identifier, and once marked "processed" it isn't read again — not even if it's forwarded to you with the same attachment.

> **Recommendation: start with a test mailbox or a scoped folder**
>
> The template is tested end to end against a real mailbox: a real message with its attachment produces a real item, gets read, extracted, validated, saved (or left awaiting your approval) and the email gets marked as processed — the whole mechanism genuinely works, not just against simulated data. Even so, before letting it run unattended against your production billing mailbox, we recommend **activating it first against a test mailbox (or a scoped folder/label of your real mailbox)** and reviewing the first jobs it produces in **Jobs** — that way you verify it with your own data and your own sheet/folder before trusting it unsupervised. The first real go-live against a customer's actual production mailbox is done as a dedicated session with the team (🔴 pending, live walkthrough) — that's a supported verification step, not a known defect.

Other honest notices about this template:

- **The supplier's tax ID isn't genuinely validated yet**: the AI extraction does obtain it, but the current piece catalog doesn't chain it into validation — that ONE field uses an internal filler value, so the tax-ID format check is disabled (the rest of the checks — amount, dates — are genuinely real).
- **Only the first attachment is processed**: if an email carries several invoices in several separate PDFs, only the first one (by position) is processed. Split those emails into separate messages.
- **Email with no attachment**: excluded from "new messages", it never generates an empty row.
- **Unreadable attachment** (a PDF with no text, for example): extraction fails BEFORE calling the AI — the item is left awaiting approval with the attachment in view, for you to complete by hand.
- **Inaccessible sheet or folder**: the task moves to "Failed" with the exact reason in its history — never a silent retry you never hear about (Manual 55, section 5, "What happens if something fails?").
- **A few missing accents in the template's text**: this template's name, description and field labels in Spanish are missing a few accent marks ("calculo", "conexion", "pestana"…) — a copy-editing oversight, already logged to be fixed in a content review; it doesn't affect what the flow does, only how it reads.

> **Note — Compliance**
>
> Emails in a billing mailbox can contain third-party data (suppliers, customers). What's extracted and where it goes is logged in the flow's history, without copying the full email — and it's deleted along with the tenant or the end customer it belongs to, in line with data-protection rules.