Export Accountant emails to Excel
Four steps, one command, and a completeness check at the end — for monthly invoice export and reconciliation.
Step 1 — connect read-only
Use an app password, never the main password. The script opens the folder in read-only mode, so nothing is marked as read or deleted.
python mail_to_excel.py --host imap.example.com --user you@example.com --days 31 --fields vendor,invoice_no,amount,vat,due_date --out accountant.xlsx
Step 2 — filter to one period
A month or a quarter, not «everything». Month-end closing starts with a list of what arrived and what is still missing. The spreadsheet is the checklist, the mailbox is the source of truth.
Step 3 — keep only the columns that matter
| Column | Why it matters |
|---|---|
vendor | Who sent the invoice — the first thing you sort by when reconciling. |
invoice_no | The unique key. Deduplicate on this column, never on the subject line. |
amount | Store as a number with a separate currency column; never sum mixed currencies. |
vat | Keep tax separate from the net amount so the report matches the ledger. |
due_date | ISO date — the column that turns a list into a payment calendar. |
Step 4 — verify completeness
- Run the same search in your mail client and note the message count.
- Compare it with the row count in the spreadsheet.
- If the numbers differ, the filter or the folder is wrong — fix it before using the file.
Example output
| vendor | invoice_no | amount | vat | due_date |
|---|---|---|---|---|
| Acme Supplies Ltd | INV-2026-1042 | 1,240.50 | 20% | 2026-10-28 |
Pitfalls
- The same invoice appears twice — Export a single folder, or deduplicate on invoice number — label copies in Gmail duplicate messages.
- Amounts do not match the bank statement — Keep the currency column and never sum mixed currencies in one column.
Provider notes
Gmail and personal Outlook accept app passwords. Corporate Microsoft 365 tenants often require OAuth, so ask IT before the first run.
FAQ
Should I export attachments too?
Yes for audit trail: keep the PDF next to the row. The script saves the folder and the spreadsheet references the file name.
How far back should the export go?
One period at a time (month or quarter). A date filter keeps the file small and the reconciliation simple.
How many messages can it handle?
Thousands per run with a date filter; very large mailboxes are better exported month by month.
Will it change anything in the mailbox?
No. Read-only access is the default and should stay enabled.
Related guides
- Accountant: columns and pitfallsThe compact overview for this role.
- Universal IMAP guideApp passwords, decoding and Excel output.