# Automating Enterprise Phishing Triage: SPF, DKIM, DMARC, and Raw Email Extraction

> How I automated phishing triage with raw .eml and .msg extraction, SPF, DKIM and DMARC alignment checks, and a KnowBe4 PAB to PhishER webhook pipeline.

- URL: https://www.kielltampubolon.id/writing/automated-phishing-triage-header-analysis/
- Author: Kiell Tampubolon
- Published: 2026-07-14
- Last updated: 2026-07-14
- Language: en
- Tags: Email Security, Security Automation

## Key takeaways

- The pipeline extracts the raw .eml or .msg artifact and normalizes headers, body and attachments, branching on file type because .msg is an OLE compound file rather than plain MIME.
- It checks SPF, DKIM and DMARC, including whether the DKIM d= domain matches the domain the user sees.
- Flagging on DMARC alignment, not just pass or fail, catches convincing spoofs that pass SPF from attacker infrastructure but do not match the displayed domain.
- User reports flow from the KnowBe4 Phish Alarm Button to PhishER, where a webhook triggers triage and writes verdicts back so analysts open a ticket with header verdicts already filled in.
- The biggest remaining gap is attachment sandboxing, since suspicious attachments still need a manual detonation step.

Most phishing triage backlogs are not a detection problem. They are a throughput problem: dozens of user-reported emails a day, each requiring the same handful of manual checks before an analyst can close it out. This is a write-up of the triage pipeline I built to take that repetitive first pass off analysts' plates.

## The manual baseline

Before automation, triage for a reported email looked like this: open the raw source, find the `Authentication-Results` header, manually read the SPF/DKIM/DMARC verdicts, check whether the visible "From" domain matched the DKIM `d=` domain, and decide whether the message was a spoof attempt or a legitimately misconfigured sender. Repeated across a queue, that adds up fast, and it is exactly the kind of check a script does more consistently than a tired analyst at 4pm on a Friday.

## Extraction and parsing

The first stage extracts the raw artifact, whether it lands as a `.eml` from a mail-flow rule or a `.msg` from Outlook, and normalizes it into a common structure: headers, body, and attachments as separate fields. Handling `.msg` specifically means parsing the OLE compound file format rather than a plain MIME message, so the extraction step has to branch on file type before anything else can run.

## Header alignment checks

With a normalized header set, the pipeline checks three things:

- **SPF** — does the sending IP appear in the authorized senders for the envelope-from domain.
- **DKIM** — does the signature verify, and does the `d=` domain match the domain the user actually sees.
- **DMARC** — does the message pass alignment (SPF or DKIM aligned with the From header domain), and what does the domain's DMARC policy say to do if it fails.

The alignment check is the one that catches the most convincing spoofs. A message can pass SPF outright because the attacker sent from their own infrastructure, and still fail DMARC because their domain does not match the one displayed to the user. Flagging on alignment, not just pass/fail, is what surfaces those cases.

## Wiring it to KnowBe4

User reports come in through the KnowBe4 Phish Alarm Button (PAB), which forwards the reported message to PhishER. From there, a webhook triggers the triage pipeline. Verdicts and extracted indicators get written back so an analyst opens a ticket that already has the header verdicts, the sender's real domain, and any URLs or attachments flagged, instead of a blank raw email to work through from scratch.

## Where AI fits

The header checks are deterministic and do not need a model. Where an AI-assisted layer helps is the ambiguous middle: a message that passes every technical check but reads like a pretext for credential harvesting, or an attachment name that is a near-miss for a legitimate vendor. That triage step runs through Microsoft Copilot Studio, orchestrated with Power Automate and a set of Python microservices that handle the actual parsing and header logic. The model does not make the close/escalate decision. It surfaces a recommendation and reasoning, and a human still signs off.

## What I would still change

The biggest gap right now is attachment sandboxing. Header and URL checks run automatically, but suspicious attachments still need a manual detonation step. That is the next piece to fold into the pipeline.

## FAQ

### How do I automate phishing email triage?

Extract the raw .eml or .msg, normalize it into headers, body and attachments, then run SPF, DKIM and DMARC checks automatically. Feeding user reports through a KnowBe4 PAB and PhishER webhook lets analysts start with verdicts already attached.

### Why does DMARC alignment matter in phishing analysis?

A message can pass SPF because the attacker sent from their own infrastructure, yet fail DMARC because their domain does not match the one shown to the user. Flagging on alignment surfaces those cases.

### Does AI make the close or escalate decision in this triage pipeline?

No. The header checks are deterministic, and the Copilot Studio layer only surfaces a recommendation and reasoning for ambiguous messages, with a human signing off.
