Export IT admin emails to Excel
Four steps, one command, and a completeness check at the end — for mailbox audits and migration checks.
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 mailbox,size,messages,last_login,forwarding --out it-admin.xlsx
Step 2 — filter to one period
A month or a quarter, not «everything». Migration and offboarding need facts: size, count, last activity and forwarding rules. Guessing here breaks migrations.
Step 3 — keep only the columns that matter
| Column | Why it matters |
|---|---|
mailbox | Which mailbox the row belongs to; essential for audits. |
size | Mailbox size — the number that decides a migration approach. |
messages | Message count; keep it next to the row count as a completeness check. |
last_login | Last activity date — the offboarding signal. |
forwarding | Forwarding status; server rules are not visible over IMAP, so record what you verified. |
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
| mailbox | size | messages | last_login | forwarding |
|---|---|---|---|---|
| sales@company.com | 12.4 GB | 48,210 | 2026-10-18 | external |
Pitfalls
- The script is throttled after a few thousand messages — Add a small delay between fetches and use a date filter; providers throttle aggressive clients.
- Forwarding rules are invisible over IMAP — IMAP does not expose server rules — check them in the admin console.
Provider notes
Microsoft 365 tenants usually disable basic auth; plan OAuth (or an export from the admin center) before the run.
FAQ
Can I audit 200 mailboxes?
Yes, loop the script over a list and keep one row per mailbox; expect hours, not minutes.
Does this change mailbox state?
No — read-only mode is enforced by the script and should never be turned off for audits.
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
- IT admin: columns and pitfallsThe compact overview for this role.
- Universal IMAP guideApp passwords, decoding and Excel output.