Export Crypto accountant emails to Excel
Four steps, one command, and a completeness check at the end — for cost basis from exchange emails.
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 exchange,trade,fee,cost_basis,period --out crypto-accountant.xlsx
Step 2 — filter to one period
A month or a quarter, not «everything». Clients rarely export complete trade history; the email trail fills the gaps and proves the missing trades.
Step 3 — keep only the columns that matter
| Column | Why it matters |
|---|---|
exchange | Which exchange or wallet provider sent the message. |
trade | Trade description (pair and side). |
fee | Fee amount with its own currency column. |
cost_basis | Cost basis value as recorded; the method is chosen by the accountant. |
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
| exchange | trade | fee | cost_basis | period |
|---|---|---|---|---|
| Kraken | BTC/USDT buy | 12.40 | 61,200 | 2026-Q3 |
Pitfalls
- Trades executed in the app never reach email — Flag those periods as incomplete instead of assuming zero activity.
- Fees are in a different currency than the trade — Keep a separate fee currency column; never convert silently.
Provider notes
Corporate mailboxes for accounting firms often enforce OAuth; confirm before relying on app passwords.
FAQ
Does this calculate cost basis?
No. It collects the rows; the method (FIFO, average) is chosen by the accountant.
What about staking rewards?
Add a «type» column and export reward notifications separately from trades.
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
- Crypto accountant: columns and pitfallsThe compact overview for this role.
- Universal IMAP guideApp passwords, decoding and Excel output.