How Post Guard AI Works
A technical overview of the architecture, email processing pipeline, and third-party services that power intelligent inbox protection.
System Architecture
Post Guard AI is a cloud-based ASP.NET Core application that connects to your email provider via IMAP, classifies every incoming message using an AI model, scans attachments for malware, and stores classification metadata in PostgreSQL — all without ever storing your email content.
Email Processing Pipeline
Every email that arrives in your inbox passes through a multi-stage pipeline. Each stage acts as a filter — only messages that are not resolved at one stage proceed to the next, keeping the process efficient.
1. IMAP Monitor Detects New Mail
The background service maintains a persistent connection to your mail server using IMAP IDLE (push notifications). When new mail arrives, the monitor wakes instantly — no polling delay.
2. Attachment Virus Scan
Every attachment is streamed to ClamAV for malware detection. If a virus is found, the email is immediately flagged, a warning banner is injected into the message body, and it is moved to the quarantine folder. No further processing occurs.
3. Duplicate & Whitelist Check
The system checks whether the message has already been processed (by message ID) and whether the sender's domain appears on the user's whitelist. Both queries run concurrently against PostgreSQL to minimize latency. Whitelisted senders pass through immediately.
4. AI Classification
The message subject, sender, classification-relevant headers, and body are assembled into a structured prompt. Only headers that influence classification (SPF, DKIM, List-Unsubscribe, etc.) are included — reducing prompt size by approximately 80%.
The prompt is sent to the cloud-hosted Ollama LLM via Microsoft Semantic Kernel. The model returns a JSON classification containing the category, risk level, confidence score, and recommended action.
{ "category": "PROMOTIONAL", "is_safe": true, "risk_level": "MEDIUM", "confidence": 0.92, "recommended_action": "ALLOW_WITH_CAUTION"}
5. User Preference Matching
The classification result is compared against your per-mailbox
preferences. For example, if you allow newsletters but block
promotions, a message classified as NEWSLETTER stays in
your inbox while a PROMOTIONAL message is moved.
6. Action — Allow or Move
Allow: The message remains in your inbox untouched.
Block: A warning banner is appended to the email body
(e.g., "This is a PROMOTIONAL email") and the message is moved to
your designated folder (e.g., Promotions).
If you disagree with a classification, simply drag the email back to your inbox. Post Guard AI detects the banner and automatically whitelists that sender's domain for future messages.
Classification Categories
Safe Email
Legitimate personal, transactional, or operational messages.
Promotional
Marketing messages designed to drive purchases or engagement.
Advertising
Brand awareness campaigns with heavy visuals and broad targeting.
Selling Product / Service
Direct sales outreach, cold emails, demo requests, and lead generation.
Spam
Phishing, scams, impersonation, malware lures, and deceptive content.
Third-Party Services & Technologies
Post Guard AI integrates with carefully selected open-source and industry-standard services. All services run on our secure cloud infrastructure — no email content is sent to third-party APIs.
MailKit IMAP / SMTP
A cross-platform .NET library for sending and receiving email. Post Guard AI uses MailKit to establish secure IMAP connections, monitor mailboxes with IDLE push notifications, fetch messages, and move classified emails between folders. Supports SSL/TLS, STARTTLS, and modern authentication.
github.com/jstedfast/MailKitOllama AI / LLM
A large language model runtime that serves AI models on our cloud infrastructure. Post Guard AI sends email content to Ollama for classification — the model runs entirely on our servers, meaning no email data is shared with third parties. The AI returns structured JSON with category, confidence, risk level, and recommended action.
ollama.comMicrosoft Semantic Kernel AI Orchestration
An open-source SDK that provides a unified API for interacting with large language models. Post Guard AI uses Semantic Kernel's Ollama connector to build chat histories, manage prompt execution settings, and parse model responses — decoupling the application from any specific model provider.
github.com/microsoft/semantic-kernelClamAV Antivirus
An open-source antivirus engine used by mail gateways worldwide. Every email attachment is streamed to ClamAV via the nClam .NET client for real-time malware detection. If a threat is detected, the message is immediately quarantined before it reaches your inbox.
clamav.netPostgreSQL Database
A powerful open-source relational database used to store user accounts, mailbox configurations, domain whitelists, and classification statistics. No email content is stored — only message IDs (to avoid re-processing) and aggregate metadata for statistics. Credentials are encrypted at rest using AES-256-GCM.
postgresql.orgASP.NET Core Web Framework
The web application framework powering the management dashboard. Built with Razor Pages, it provides mailbox configuration, real-time email statistics, user management, and system administration — all secured with cookie authentication, TOTP two-factor authentication, and role-based authorization.
dotnet.microsoft.comSecurity & Privacy by Design
Private Cloud AI Processing
The AI model runs on our dedicated cloud servers via Ollama. No email content is shared with third-party services.
No Email Storage
Only message IDs and classification metadata are stored. Your actual email content is never persisted.
AES-256-GCM Encryption
All stored credentials (IMAP passwords, TOTP secrets) are encrypted at rest using AES-256-GCM with PBKDF2-derived keys.
Two-Factor Authentication
User accounts support TOTP-based 2FA, compatible with Google Authenticator, Microsoft Authenticator, and Authy.
Data Flow Summary
| From | To | Protocol | Purpose |
|---|---|---|---|
| Email Provider | Post Guard AI |
IMAP/SSL
|
Fetch & monitor new messages via IDLE |
| Post Guard AI | Ollama (cloud) |
HTTP
|
Send email text for AI classification |
| Post Guard AI | ClamAV (cloud) |
TCP
|
Stream attachments for virus scanning |
| Post Guard AI | PostgreSQL |
TCP/SSL
|
Store metadata, whitelist, user settings |
| Post Guard AI | Email Provider |
IMAP/SSL
|
Move classified emails between folders |
At a Glance
| Mail Connection | Securely connects to Gmail, Yahoo, Outlook, and other providers via IMAP over SSL/TLS using MailKit. Monitors your inbox in real time with IMAP IDLE push notifications. |
| Virus Detection | Every attachment is streamed to ClamAV (via the nClam client) for malware scanning. Infected messages are quarantined immediately — before any other processing occurs. |
| AI Classification | Email content is classified by a large language model served by Ollama, orchestrated through Microsoft Semantic Kernel. Messages are categorized as Safe Email, Newsletter, Promotional, Advertising, Selling Product/Service, or Spam — each with a confidence score and risk level. |
| Your Preferences | You choose which categories to allow and which to block on a per-mailbox basis. Blocked emails are moved to a designated folder with a warning banner. Drag a message back to your inbox to automatically whitelist that sender's domain. |
| Data Storage | PostgreSQL stores only user accounts, mailbox settings, domain whitelists, and classification statistics. No email content is ever stored. All credentials are encrypted at rest with AES-256-GCM. |
| Security | Built on ASP.NET Core with cookie authentication, TOTP two-factor authentication, role-based authorization, and encrypted credential storage. AI processing runs on our cloud infrastructure — no email data is shared with third-party services. |
Post Guard AI combines real-time IMAP monitoring, AI-powered classification, antivirus scanning, and user-defined filtering into a single pipeline — keeping your inbox clean, secure, and under your control.
Back to Home