A Defender for Office 365 report that tells the story
Ask a customer "how is your mail security doing?" and you usually get a screenshot of the Defender portal. A few donut charts, a number of blocked messages, and a feeling that it's probably fine. Then the follow-up questions start. Is that more than last month? Which policy actually stopped it? Are there threats sitting in a mailbox right now? Why is half our mail coming from countries we don't do business with?
The data to answer all of that is there, in advanced hunting. Nobody wants to write twenty queries before every monthly meeting. So I wrote them once, and built a report around them.

What it does
One command per customer, run right before the meeting:
bashpython3 -m mdoreport --config Fabrikam/Fabrikam.toml
It runs the KQL queries through the Microsoft Graph hunting API, saves the figures per day, and writes an HTML report and a PDF. One for the whole tenant and one per mail domain, each compared with the previous 30 days.
- Read-only, one permission. The app registration only needs
ThreatHunting.Read.All. It can't change a policy, release a message or read a mailbox. - Nothing to install. Python standard library only. The PDF is printed by the Chrome or Edge that's already on the machine.
- Every number is traceable. Each run keeps the query results as CSV and every query exactly as it ran, ready to paste into advanced hunting. When someone asks "where does this number come from?", the answer is a file, not a shrug.
Start with the answer
The first page is for the person who has five minutes. Three status cards (mail flow, delivered threats, outbound mail), the key findings with a link to the details, and what changed compared with the previous period.

Everything below that is for the people who want to dig in: 24 sections, each one answering a single question. Every section can be switched off in the parameter file, so a customer without Plan 2 features or without priority accounts doesn't get empty pages.
Mail flow and verdicts
The basics first: how much mail came in per day, and what happened to it.

One thing I learned the hard way: blocked is not the same as a threat. A big share of blocked mail has no verdict at all. It failed or was dropped before Defender ever judged it. If you add that to the phish count, your numbers look scary and wrong. The report keeps the two apart.

What actually stopped it
For me this is the most useful section. Which policy acted on the mail, per day? Is it the anti-spam policy doing all the work, or are the impersonation settings finally earning their keep? And which mail was stopped without any policy named?

Where does the mail come from?
My favourite section. It looks at the top-level domain of every sender (.be, .com, .ru and so on) and shows how much of the mail from each one was blocked, on a world map and a map of Europe.

The maps are drawn from public domain Natural Earth borders that ship with the tool, so the report needs no internet connection and loads nothing from a third party.

A caveat I put in the report itself: a top-level domain is not a country. .com says nothing about where a mail comes from, and a country block in a mail flow rule usually looks at the sending server's IP address, not at the domain. The map shows patterns, not geography. It's still very good at starting the conversation: "why do we accept mail from that TLD at all?"
Beating the 30-day limit
Advanced hunting keeps 30 days of data. That's a problem for a monthly report, and a bigger one for trends. The fix is simple: every run saves its figures per day in a history file. The report reads its days from that history, so a day saved by an earlier run is still there after Defender has forgotten it. A small "collect" run halfway between two meetings keeps the history without gaps.

The details that matter
- Phishing simulations are left out of every number (and the appendix says how many). Otherwise your own awareness campaign shows up as an attack.
- SecOps mailboxes receive malicious mail on purpose. They're excluded from the numbers too.
- User addresses can be masked (
j***@contoso.com, subjects left out) for reports that go to a wider audience. - Check the values, not just the columns. Microsoft documents the columns of the mail tables, not what's in them. A small helper counts the values per column in a real tenant (without reading any addresses or content) so the queries match reality.
What I'd tell myself at the start
- Start from the questions the customer asks in the meeting, not from the tables you have.
- Build the demo tenant first. Every screenshot in this post comes from invented data, generated by the same code that builds real reports. That made testing easier, and it makes posts like this one possible without leaking anything.
- One page that people read beats fifty pages that are complete.