Overview of the Product

Mail2CRM is an in-house SCAND product built as a boilerplate for companies whose sales happen in email. It can be delivered as is or adapted to a customer's own workflow, product catalog, and document requirements.

The product is a classification agent that also works as an AI sales agent for email-based sales. It follows every lead through a defined workflow based on the email thread, and for each incoming message, it suggests the text of the next reply. It never sends anything itself: the salesperson reads the draft, edits it if needed, and sends it from their own mailbox or automatically via application but only after approval.

The demo setup is a B2B seller of custom ice hockey equipment (skates, sticks, and jerseys in different sizes) with three warehouses and delivery prices that depend on the EU region. Catalog, warehouses, required documents, and prompts are plain files, so the same system can be reconfigured for another business without code changes to the agent.

  • Industry: Sales / CRM Automation (demo: B2B sports equipment)
  • Application Type: AI agent with a web back office
  • Timeline: 1 month

Challenge

For many small and mid-sized sales teams, the inbox is the primary tool for email lead management and the de facto CRM. Deal status lives in people’s heads, documents are scattered across threads, and nobody can say at a glance which leads are waiting for an answer.

Handing this work to a language model creates new problems. A model that picks the deal status on its own can skip stages or contradict the previous decision. A model that calculates a quote can get the arithmetic wrong, and a model that sees internal cost can leak it into a customer letter. An agent that sends email by itself turns every such mistake into a message the customer has already read.

Inbound email is also untrusted input. Anyone can write to a sales address, so a message may contain instructions aimed at the agent instead of the salesperson.

The task was therefore not to connect a model to a mailbox, but to build an agent whose decisions are predictable, whose numbers are exact, and whose output always passes through a person’s review.

Main Goals

The project focused on a working product that could be shown to customers and adapted quickly. We defined the following goals:

  • Ingest incoming and outgoing mail from a mailbox and process it through a queue.
  • Classify every lead by stage: new, qualification (including the check of KYC documents), negotiation, contract, closed, cancelled.
  • Base each decision on the recent email history, the price catalog, the KYC document list, warehouse locations, and delivery prices.
  • Draft a recommended reply for each stage and store it for a human, with no automatic sending.
  • Keep the stage decision deterministic so that no model output can skip a step.
  • Compute all prices and totals in code, and keep internal costs out of every prompt.
  • Detect prompt injection in inbound email before any model sees it.
  • Provide a back office with a dashboard, customer list, correspondence, documents, and pending actions.
  • Keep the business knowledge in editable files so the product can be re-targeted to another catalog and workflow.
  • Run on an open-weight model so customers are not tied to one vendor and have the option to keep business data safe.
  • Cover the agent’s behavior with automated tests.

Project Overview

We started with a product specification and an architecture document, then split the work into features.

  • Runtime. One TypeScript codebase, two processes, one PostgreSQL database. A worker ingests mail over IMAP, stores messages and attachments, and queues inbound/outbound mail for the agent.
  • Agent. A LangGraph agent (state graph) extracts facts and the order from the email and recent history.
  • The model never chooses the status: Code derives it, one legal step at a time.
  • Quotes. Prices, delivery, revenue, and totals are computed in code, and every amount in the letter is audited against the catalog.
  • Security. Inbound email is scanned for prompt injection before any model call, and flagged messages are quarantined for review.
  • Back office. A Next.js app with a dashboard, the action queue, and a customer page showing the thread, deal, documents, and recommended letter.

Agent Workflow

The model only reads the email. Code sets the stage and the numbers, and a person sends the reply.

Inside the agent, each email runs through a LangGraph state graph. The injection check runs first; a flagged email goes straight to quarantine. Clean mail is enriched with history, then two LLM steps run in parallel: one classifies deal signals, while the other extracts the order. The decide node routes the result to a stage-specific draft, a free-form chat answer, or no letter. Finally, applyRules checks every proposed stage change against the allowed transitions and enforces valid changes in code, preventing the LLM from moving a lead to an unauthorized stage.

Solution

The result is a working email-driven CRM that a company can put next to its existing mailbox. Sales staff keep writing emails the way they do now. The system keeps the pipeline up to date, files the documents, and has a draft ready for the next step.

For a new customer, adaptation means editing the knowledge files: the product catalog with prices, the warehouses and delivery zones, the list of required documents, and the stage prompts. Beyond the knowledge files, the workflow itself can be changed: the team can add extra checks and connect external systems such as an ERP or a CRM.

Core Application Capabilities

  • IMAP ingest of incoming and sent mail, with attachments stored and linked to the customer and deal
  • Queue-based processing with retries, duplicate protection, and recovery of unprocessed mail on restart
  • Lead classification across six stages: new, qualified, negotiation, contract, closed, cancelled
  • Deterministic stage transitions derived in code from facts the model extracts
  • Stage-specific recommended replies for qualification, negotiation, and contract
  • Free-form answers to general questions through a tool-using sub-agent
  • Order extraction with validation against the knowledge base, including mixed and amended orders
  • Code-computed quotes with warehouse selection and delivery price by region
  • Audit of every currency amount in a drafted letter
  • Price-only catalog for the model, so internal cost never reaches a prompt
  • Prompt injection scanning and quarantine of inbound email
  • Full audit record of every agent run
  • Dashboard with counters, pipeline, action queue, recent documents, and 30-day deal charts
  • Customer workspace with status history, correspondence, deal value, expected profit, and documents
  • File-based knowledge: catalog, warehouses, KYC documents, and prompts
  • Works with any LLM, closed or open-weight, via an OpenAI-compatible API
  • Prompt injection detection with the JEV classifier (or custom local option)
  • Security checks that cover the OWASP Top 10 risks for agentic applications

Guardrails Built into the Agent

  • Human approval. The agent never sends email. A salesperson reads, edits, and sends every reply.
  • Stages set by code. The model extracts facts, while application code applies the permitted transition. The model cannot skip a stage or reopen a closed deal.
  • Exact numbers. Prices, delivery, and totals are computed in code, and every amount in a letter is audited against the catalog.
  • No internal cost in prompts. The model works with a price-only catalog.
  • Prompt injection scan before any model call. Flagged mail is quarantined, and processing stops if the detector is unavailable.
  • Full audit record of every agent run.

Inside the Back Office

AI sales pipeline dashboard with deal tracking and action queue
The dashboard shows new emails, actions due today, the pipeline by stage, and an action queue drafted by the agent.
AI-powered customer workspace for managing sales deals and email correspondence
The customer workspace shows the status map, the current deal, the drafted reply ready to copy, the full correspondence, and every filed document.
Prompt injection detection and security review in the AI email agent
When an email looks like a prompt injection, the agent does not read or answer it, and the deal stage stays unchanged. The salesperson sees the detector's verdict and the suspicious text, and decides what to do.

Technology Stack

The product uses the following technology stack:

Language

  • TypeScript

Agent

  • LangGraph (state graph)

LLM

  • OpenAI gpt-oss-120b, an open-weight model, accessed through an OpenAI-compatible API

Database

  • PostgreSQL

Back Office

  • Next.js
  • React
  • Tailwind CSS
  • Recharts

Security

  • Prompt injection detector (JEV)
  • JWT

Development Methodology

  • Spec-driven development

Results

Mail2CRM takes over the routine part of lead handling and automates the sales pipeline from the inbox and leaves the decision to send to a person.

Automation

  • 6 of 7 routine steps per inbound email (about 86%) are automated: matching the sender to a customer, filing the message, filing the attachments, updating the deal stage, calculating the quote, and drafting the reply. The one step left to a person is review and send.
  • 100% of deal stages are covered: all six stages are tracked, and a draft is prepared at every stage that needs a reply.
  • 100% of inbound emails end with a recorded next action, so no lead waits unnoticed in the inbox.
  • Scaling. The solution can help scale sales activities to thousands and more processed emails per day.

Safety

  • Human-based approval. By design, every message a customer receives has been read and sent by a person.
  • 100% of inbound emails are scanned for prompt injection before any model call when the security layer is on. Flagged messages are quarantined, and if the detector is unavailable, processing stops instead of continuing unprotected.
  • 100% of stage changes pass a transition check in code, so the model cannot skip a stage or reopen a closed deal.
  • 0 internal cost figures reach the model: it works with a price-only catalog.

Mail2CRM vs. Manual Handling

TaskSalesperson by handMail2CRM
Prices and totals in a quoteLooked up and retyped, so slips are possible100% computed in code from the catalog, and every amount in the letter is audited
Deal stageDepends on who updates the CRM and whenUpdated on every email, and the same facts always give the same stage
CRM record and letterEntered twice, so they can drift apartOne source: the deal record and the letter use the same quote
Reading the email (intent, order lines)Reliable but slowDone by the model, so it can misread; the order is validated against the catalog and a person reviews the draft

Core Team

  • AI Engineer: Designed the agent graph, prompts, deterministic decision rules, quote logic, and the injection quarantine.
  • Backend Developer: Built the mail ingest, the processing queue, the CRM data model, and the migrations.
  • Frontend Developer: Built the back office: login, dashboard, customer list, and customer workspace.
  • QA Engineer: Prepared test scenarios and automated checks of the agent’s behavior.

Get in Touch with Us

Please enter your name.
Please enter a subject.
Please enter a message.
Please agree to our Terms and Conditions and the Privacy Policy.

This site uses technical cookies and allows the sending of 'third-party' cookies. By continuing to browse, you accept the use of cookies. For more information, see our Privacy Policy.