Developer Tools

How to Organize Outlook Email Alerts into Priority Folders with AI Agent

For years my inbox was a wall of alerts. CI failures, AWS notices, backup reports, Jira tickets, cost anomalies, thousands of them, all mixed…

How to Organize Outlook Email Alerts into Priority Folders with AI
Share:

How to Organize Outlook Email Alerts into Priority Folders with AI Agent

8 min read
22 views

For years my inbox was a wall of alerts. CI failures, AWS notices, backup reports, Jira tickets, cost anomalies, thousands of them, all mixed with real messages from real people. I had folders, but folders per tool weren’t enough. I still couldn’t tell at a glance what needed me now and what was just a robot saying “all good”.

This post shows how I finally managed to organize Outlook email alerts into four priority tiers (P1 to P4) by letting an AI agent build the folders and rules for me. I used Claude Code, but any AI agent that runs in your terminal can follow the same steps. No Microsoft Graph app and no admin consent, just the access I already had as a regular user.

Advertisement

The Story: Copilot First, Then Claude

My company’s Outlook ships with Copilot Chat built in, so that was my first try. It did create folders and rules, which honestly surprised me. But it was buggy: it made duplicate folders and duplicate rules, and I spent more time cleaning up after it than it saved.

That got me thinking. If Copilot can reach my mailbox, there has to be an API for this. So I asked Claude Code (Anthropic’s AI coding agent that runs in your terminal) to research the options with me. Here’s what we found:

OptionWhat you needCatch
Microsoft Graph APIApp registration plus admin consentMost company IT teams block this
Exchange Online PowerShellInstall a module and sign inOften restricted for non-admins
Classic Outlook (COM)Classic Outlook already installedOutlook window must stay open while you work

The winner was the old one. COM (Component Object Model) is a Windows feature that lets scripts control desktop apps, a bit like a remote control for Outlook. Classic Outlook exposes its rules engine through COM, and the rules it saves are server-side, meaning they live in your Exchange mailbox and work in new Outlook and Outlook on the web too. And because it runs as you, on your own laptop, it needs no extra permissions.

Advertisement

The P1 to P4 Idea

Before touching any code, decide how urgent each kind of alert is. I borrowed the priority levels incident teams use:

TierMeaningExamples
P1 – Action RequiredDo something todayCI pipeline failed, token expiring, server recovery failed, site down
P2 – InvestigateLook into it soonCloudWatch-style alarms, cost anomalies, backup warnings, security scanner findings
P3 – ReviewRead when you have timeWeekly reports, cloud health notices, ticket updates, merge requests
P4 – AutomatedConfirmation only, no actionBackup success, CI resolved, certificate renewed, auto-recovery done

Each tier is a top-level folder with subfolders per source, for example P1 - Action Required/GitLab CI or P4 - Automated/Backup Success. Emails from humans stay in the Inbox, which is the whole point: the Inbox becomes people again.

Which AI Agent Should You Use?

You don’t need a specific one. The agent only has to run PowerShell commands on your Windows machine and ask before it changes anything. Here are good choices:

AI AgentWhy pick it
Claude Code (Anthropic)What I used and my top pick. Great at reading scan output, suggesting a mapping, and fixing errors as it goes.
Codex CLI (OpenAI)A solid choice if you already have a ChatGPT plan. Same workflow, same prompt.
Any other CLI agentGemini CLI, GitHub Copilot CLI, and similar tools work too, as long as they can run PowerShell and wait for your approval.

Whichever you pick, use the one your company allows for work data.

Quick Option: Let an AI Agent Set It Up for You

Your AI agent can run PowerShell on your machine and do the boring parts (scanning senders, creating rules) while you approve each step. If you use Claude Code and haven’t set it up yet, see How to Install and Configure Claude Code CLI on Windows PowerShell. Paste this prompt into your agent:

I want to organize alert and notification emails in my Outlook mailbox into
priority folders: "P1 - Action Required", "P2 - Investigate", "P3 - Review",
"P4 - Automated", each with subfolders per alert source. Use classic Outlook
through COM from PowerShell on Windows. Ask me before making any change.

1. Check that classic Outlook is installed and open a window on the Inbox so
   the session is online.
2. Read only: scan the newest 3000 Inbox items and group them by sender
   address and normalized subject. Show me the top automated senders.
3. Propose a mapping table: sender/subject pattern, target folder, tier.
   Wait for my approval.
4. Create any missing folders, run SendAndReceive, and wait a few minutes so
   the folders sync to the server before any rule points at them.
5. Create one server-side rule per mapping with "stop processing more rules".
   Order rules so failures (P1) come before success notices (P4) for the same
   sender. Set MoveToFolder.Folder with InvokeMember SetProperty.
6. Print every rule with its order, target folder, and IsLocalRule value.
7. Do NOT run rules against existing mail. I will run them myself.

Guardrails: never delete or move emails, never delete or change rules or
folders you did not create, never touch emails from people, never ask me
for passwords or tokens.

Read every command before you approve it. The manual steps follow below if you’d rather do it yourself.

Prerequisites

  • Windows with classic Outlook (the Microsoft 365 desktop app) signed in to your work mailbox. New Outlook doesn’t support COM.
  • PowerShell 7 (pwsh). Note that this one runs on Windows itself, not in WSL2 Ubuntu, because COM is a Windows-only feature.
  • Optional: an AI agent CLI such as Claude Code or Codex to drive it. For a full Windows setup with AI tools, see How to Set Up a DevOps Onboarding Environment on Windows with WSL2 and AI Tools
  • Your company’s OK to use an AI tool with work email. The scan in Step 2 shows sender addresses and subject lines, so check your IT or AI usage policy first.

Step-by-Step Guide

Step 1: Open Classic Outlook and Connect from PowerShell

Keep a classic Outlook window open. If Outlook only runs in the background, rule calls fail with “You are currently working offline”, even when it’s online.

$ol = New-Object -ComObject Outlook.Application
$ns = $ol.Session
if ($ol.Explorers.Count -eq 0) { $ns.GetDefaultFolder(6).Display() }
$ns.DefaultStore.GetRules().Count
  • New-Object -ComObject Outlook.Application: attaches to Outlook
  • GetDefaultFolder(6): 6 is the Inbox; .Display() opens a window on it
  • GetRules().Count: if this prints a number, you’re connected and can manage rules

Step 2: Find Out Who Is Flooding Your Inbox

You can’t write good rules from memory. This read-only scan groups recent mail by sender and subject pattern, replacing numbers with # so “Backup Report 101” and “Backup Report 102” count as one pattern.

$items = $ns.GetDefaultFolder(6).Items
$items.Sort('[ReceivedTime]', $true)
$stats = @{}
$i = 0
foreach ($m in $items) {
    if ($i++ -ge 3000) { break }
    if ($m.Class -ne 43) { continue }
    $pattern = $m.Subject -replace '\d[\d,.:/-]*', '#'
    $key = "$($m.SenderEmailAddress) | $pattern"
    $stats[$key] = 1 + [int]$stats[$key]
}
$stats.GetEnumerator() | Sort-Object Value -Descending | Select-Object -First 60
  • Class -ne 43: skips anything that isn’t a normal email (meeting invites, reports)
  • The output is your raw material: the top senders are almost always automated

My scan of about 3,200 emails showed the top 10 senders were all machines. One cloud health sender alone had 658 messages. That’s the moment the P1 to P4 plan stopped feeling like overkill.

Step 3: Create the Folders First and Let Them Sync

$root = $ns.GetDefaultFolder(6).Parent
$p1 = $root.Folders.Add('P1 - Action Required')
[void]$p1.Folders.Add('GitLab CI')
$ns.SendAndReceive($false)

This is the step that bit me. Classic Outlook works in cached mode, so a new folder exists on your laptop before it exists on the server. If you create a rule that points at it too soon, the server marks the rule invalid and new Outlook shows it with a red X, turned off. Create the folders, sync, give it a few minutes, then create the rules.

Step 4: Create a Rule

Here’s one complete rule: emails from a CI tool whose subject says “new failure” go to P1 - Action Required/GitLab CI.

$rules = $ns.DefaultStore.GetRules()
$rule  = $rules.Create('P1 - GitLab CI Failure', 0)

$rule.Conditions.SenderAddress.Address = [string[]]@('ci-alerts@example.com')
$rule.Conditions.SenderAddress.Enabled = $true
$rule.Conditions.Subject.Text = [string[]]@('new failure', 'failed')
$rule.Conditions.Subject.Enabled = $true

$target = $root.Folders.Item('P1 - Action Required').Folders.Item('GitLab CI')
$move = $rule.Actions.MoveToFolder
[void][System.__ComObject].InvokeMember('Folder', [Reflection.BindingFlags]::SetProperty, $null, $move, @($target))
$move.Enabled = $true

$rule.Actions.Stop.Enabled = $true
$rules.Save()
  • Create(name, 0): 0 means a rule for incoming mail
  • SenderAddress: matches if the sender address contains any listed text
  • Subject.Text: matches if the subject contains any of the words (OR); two different conditions are combined with AND
  • InvokeMember(...): sets the target folder. A plain $move.Folder = $target silently does nothing from PowerShell, and the save then fails with “invalid actions or conditions”
  • Actions.Stop: “stop processing more rules”, so one email lands in exactly one folder

In practice you’ll have dozens of rules (I ended up with 38), so keep them as a list in one script and loop over it. That way you can delete and recreate them all whenever you tweak something.

Step 5: Get the Rule Order Right

Rules run top to bottom. Same sender can mean P1 or P4 depending on the subject, so order matters:

Advertisement
  1. P1 failure rules (Deploy Failed, Recovery Failed)
  2. P4 success rules for the same sender (Deploy Succeeded)
  3. A catch-all for that sender last, so anything new and unknown lands in P2 for a human to look at

Set $rule.ExecutionOrder as you create each rule, then print them all with IsLocalRule. You want False on every one; that confirms it’s a server-side rule.

Step 6: Run the Rules on Old Mail (Your Call)

Rules only apply to mail that arrives after they’re created. For the backlog, I preferred to run them myself, one at a time, so I could check each folder: File > Manage Rules & Alerts > Run Rules Now, pick the rule, choose the Inbox, and click Run Now. Go in rule order, or a catch-all rule will grab emails meant for P1.

Gotchas I Hit Along the Way

SymptomCauseFix
“You are currently working offline”Outlook running with no windowOpen a classic Outlook window, then retry
“One or more rules cannot be saved”Target folder never got setUse InvokeMember to set MoveToFolder.Folder
Red X, rule disabled in new OutlookFolder not synced to server yetWait a few minutes, then recreate the rule
Internal sender never matchesSender is an Exchange address, not SMTPUse the From condition instead of SenderAddress
Old alerts still in InboxRules only act on new mailRun Rules Now per rule

One more tip: saving after every single rule is slow because each save rewrites the whole rule set on the server. Build all rules, then call $rules.Save() once.

The Result

My Inbox went from 700+ unread to a handful of emails from actual people. When I open Outlook now, I check P1 first, glance at P2, and ignore P4 unless something looks off.

organize Outlook email alerts

Need a new rule? I take a screenshot of the email, tell Claude where it belongs, and it updates the script and recreates the rules in under a minute.

If you try this, start small: pick your top five noisiest senders, give them a tier, and grow from there. You don’t need the perfect folder tree on day one.

Conclusion

You set up P1 to P4 priority folders and server-side Outlook rules using classic Outlook COM and PowerShell, with an AI agent like Claude Code or Codex doing the heavy lifting and no admin permissions required. If you want to package this kind of workflow so you can reuse it, check out How to Build and Deploy a Custom Claude Code Plugin with Skills, or see what else an AI agent can build in an afternoon in How I Built 3 Browser Games in One Day With Claude AI.

Recommended for Linux builders

Contabo VPS hosting for Linux projects

Run Linux servers, automation tools, and self-hosted apps on a Contabo VPS with generous resources and predictable pricing.

Our customers sayExcellent4.6 out of 5 based on 11,008 reviews Trustpilot

Some links are affiliate links. This may earn LinuxBeast a commission at no extra cost to you.

Privacy settings

Choose which privacy controls to open.

Opening these controls does not change your saved choices.