Export Agency owner emails to Excel
Four steps, one command, and a completeness check at the end — for per-client reporting from inbox.
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 client,campaign,spend,result,period --out agency-owner.xlsx
Step 2 — filter to one period
A month or a quarter, not «everything». Client reporting starts with what was agreed over email. A per-client export turns those agreements into numbers you can defend.
Step 3 — keep only the columns that matter
| Column | Why it matters |
|---|---|
client | The join key for every other report you will build later. |
campaign | The campaign or project the client paid for. |
spend | Budget spent, with a currency column. |
result | The outcome metric agreed with the client. |
period | Month or quarter, so each export is a closed, auditable slice. |
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
| client | campaign | spend | result | period |
|---|---|---|---|---|
| GlowStudio | Autumn promo | 1,800 | 42 leads | 2026-09 |
Pitfalls
- Reports mix currencies and time zones — Store currency and timezone columns explicitly; never infer them from the amount.
- One client’s data leaks into another report — One folder or label per client, one export per client.
Provider notes
Agency accounts on Google Workspace often need OAuth because admins disable app passwords.
FAQ
Can I automate monthly client reports?
Yes: schedule the export, then build the report from the file with the same column names every month.
How do I handle client-specific fields?
Keep a shared core of columns and add a client-specific sheet; do not fork the schema per client.
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
- Agency owner: columns and pitfallsThe compact overview for this role.
- Universal IMAP guideApp passwords, decoding and Excel output.