◈ Mail → Excel

Export IT admin emails to Excel

By the Mail → Excel team · Updated 2026-10-20

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

ColumnWhy it matters
mailboxWhich mailbox the row belongs to; essential for audits.
sizeMailbox size — the number that decides a migration approach.
messagesMessage count; keep it next to the row count as a completeness check.
last_loginLast activity date — the offboarding signal.
forwardingForwarding status; server rules are not visible over IMAP, so record what you verified.

Step 4 — verify completeness

  1. Run the same search in your mail client and note the message count.
  2. Compare it with the row count in the spreadsheet.
  3. If the numbers differ, the filter or the folder is wrong — fix it before using the file.

Example output

mailboxsizemessageslast_loginforwarding
sales@company.com12.4 GB48,2102026-10-18external

Pitfalls

Provider notes

Microsoft 365 tenants usually disable basic auth; plan OAuth (or an export from the admin center) before the run.

Ready-made: the $3 script implements these steps and writes the Excel file with the columns above. Get the script.

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