Email Processing Pipelines with Haystack

Combine Haystack's composable pipeline architecture with MultiMail's email infrastructure to build RAG-powered email agents that retrieve, reason, and respond.


Haystack is an end-to-end NLP framework by deepset for building search and RAG pipelines. Its composable architecture lets you snap together retrievers, generators, and custom components into processing pipelines. MultiMail provides the email infrastructure layer that turns Haystack's retrieval and generation capabilities into production email workflows.

By integrating MultiMail with Haystack, you can build pipelines that process inbound emails, retrieve relevant context from document stores, generate informed responses, and send replies through managed mailboxes. MultiMail's gated_send mode ensures that RAG-generated replies are reviewed for factual accuracy before reaching recipients.

Connect Haystack to MultiMail by creating custom pipeline components that call the MultiMail REST API. Haystack's component model makes it natural to add email input/output stages to any pipeline.

Built for Haystack developers

Pipeline-Native Email Components

Create custom Haystack components for email operations that integrate seamlessly into your pipelines. An EmailFetcher component can pull from MultiMail's inbox, and an EmailSender component can deliver generated responses.

RAG-Powered Email Responses

Haystack excels at retrieval-augmented generation. Combine its retriever and generator components with MultiMail to build pipelines that answer emails based on your knowledge base, ensuring responses are grounded in actual data.

Human Review for Generated Content

RAG pipelines can still produce inaccurate responses. MultiMail's gated_send mode adds a human review step between Haystack's output and actual email delivery, catching errors that retrieval alone cannot prevent.

Email Indexing Pipeline

Build a Haystack pipeline that fetches emails from MultiMail and indexes them into a document store. This makes your email history searchable and retrievable for future context-aware responses.

Composable Email Workflows

Haystack's pipeline architecture lets you compose complex email workflows from simple components. Chain classification, routing, retrieval, generation, and sending stages into end-to-end email processing pipelines.


Try it with your agent

No code, no dashboard. Paste this to your AI agent — it connects MultiMail, creates an inbox, and builds the flow for you.

1. Get MultiMail ready: read https://multimail.dev/llms.txt, connect the MultiMail MCP server in your agent environment, create a free inbox, and set up a verified sending domain so the agent can receive and send mail. 2. Wire MultiMail into Haystack using Haystack’s Tool abstraction: expose three callable tools to the Haystack agent, backed by the connected MultiMail MCP server, for checking the inbox, composing a draft reply, and sending or scheduling an email. 3. Build the Haystack flow as a composable pipeline: use your normal retriever and prompt-building components for RAG context, then let the Haystack agent decide when to call the MultiMail inbox-check, draft-reply, and send tools while answering email. 4. Send a test email to the new MultiMail inbox, run the Haystack agent once, have it retrieve any relevant context, inspect the incoming message, draft a reply, and prepare the outbound email through MultiMail. 5. Run MultiMail in gated_send oversight mode for this quickstart: every prepared send must stop for developer review and approval before anything is sent; only move to monitored or autonomous after you have tested the agent’s behavior.

Step by step

1

Create a MultiMail Account and API Key

Sign up at multimail.dev, create a mailbox, and generate an API key. Your key will start with mm_live_.

2

Install Dependencies

Install Haystack and requests for calling the MultiMail API.

3

Create Custom Components

Build Haystack @component classes for EmailFetcher and EmailSender that wrap MultiMail API endpoints.

4

Build Your Pipeline

Compose your email processing pipeline by connecting components: fetcher, retriever, prompt builder, generator, and sender.

5

Run and Review

Execute the pipeline. Review and approve pending emails in the MultiMail dashboard when using gated_send mode.


Common questions

How do I create a Haystack component for MultiMail?
Use Haystack's @component decorator to create custom components that call the MultiMail REST API. Define input and output types using @component.output_types, and implement the run() method to make API calls. Components integrate into pipelines just like built-in Haystack components.
Can I index my email history into a Haystack document store?
Yes. Build an indexing pipeline with an EmailFetcher component, document preprocessors (cleaner, splitter), and a DocumentWriter. This indexes your MultiMail emails into any Haystack-compatible document store for semantic search and retrieval in future response generation.
What oversight mode works best for RAG email pipelines?
Start with gated_send to review every RAG-generated reply before delivery. As your pipeline proves reliable, consider monitored mode where emails send immediately but remain visible for review. Autonomous mode should only be used for thoroughly tested, high-confidence response pipelines.
Can I use Haystack's evaluation tools to measure email response quality?
Yes. Haystack provides evaluation components for measuring RAG quality metrics like faithfulness and relevance. Run your email response pipeline through evaluation before switching from gated_send to less restrictive oversight modes, building quantitative confidence in your pipeline's output quality.
Does Haystack support streaming for email generation?
Haystack's generator components support streaming, which is useful for long email drafts. However, the final email is sent to MultiMail as a complete message via the REST API. Streaming is most beneficial for user-facing previews of the draft before it enters MultiMail's approval queue.

Explore more

The only agent email with a verifiable sender

Email infrastructure built for AI agents. Verifiable identity, graduated oversight, and a hosted MCP server. Formally verified in Lean 4.