DEV Community

Cover image for Postmark + RAG = Email Assistant 2.0
VerΓ­ssimo Cassange
VerΓ­ssimo Cassange

Posted on

Postmark + RAG = Email Assistant 2.0

This is a submission for the Postmark Challenge: Inbox Innovators.

What I Built

A virtual assistant solution based on RAG (Retrieval Augmented Generation) for VerdeVive. The system processes incoming emails, uses an AI model to generate contextual responses and automatically replies to customers.

Here's a quick look at how it works:

  • It picks up customer emails through Postmark's inbound processing.
  • Next, it uses natural language processing to understand the questions customers are asking.
  • Then, it digs into our knowledge base, finding the most relevant information through vector similarity search.
  • After that, an LLM (Large Language Model), specifically via Groq, crafts contextually appropriate and accurate responses.
  • Finally, it sends out a professional, well-formatted email response to the customer in an instant.

What sets this solution apart from a typical chatbot? It delivers factually correct information directly related to VerdeVive's product catalog and our commitment to sustainability. All of this happens seamlessly through the email interface our customers already use and trust.

Why I Used RAG πŸ€–

I used RAG (Retrieval-Augmented Generation) at VerdeVive to develop a virtual assistant that distances itself from traditional chatbots. This approach allows responses to be generated from information extracted directly from our content.md file, which concentrates key data about the company, such as mission, products, and initiatives. In this way, we ensure that the assistant accurately represents our identity and values while avoiding the high costs associated with training extensive models.

Demo

Demo Links:

Example questions to try:

  • "What sustainable products do you sell?"
  • "Tell me about your partnerships"
  • "How do your products help the environment?"

πŸ“¨ I Sent a Question

I asked the following question via email:

"What sustainable products do you sell?"

Sent question


βœ… I Received the Answer

The application successfully received and processed the response:

Received answer

Testing Instructions:
1️⃣ Simply send an email to [email protected] with your question in the body.
2️⃣ You'll then receive an automated response with information relevant to your inquiry.
3️⃣ Response times are typically under 2 minutes, so you won't be waiting long!

Code Repository

For more technical details, you can access my repository and follow the step-by-step described in the README.

GitHub logo vec21 / email-ai-assistant

AI-powered email assistant that uses RAG technology to automatically respond to inquiries with accurate, context-aware information.

VerdeVive Assistant 🌱

A virtual assistant based on RAG (Retrieval Augmented Generation) that processes received emails, generates contextual responses, and automatically replies to VerdeVive customers.

πŸ“‹ Description

VerdeVive Assistant is an automated customer service solution that uses AI technology to process customer emails and generate personalized responses based on company documentation. The system integrates with the Postmark service to receive and send emails, and uses an advanced language model (Llama3) through the Groq API to generate contextual and relevant responses.

πŸ› οΈ Technologies

  • Backend Webhook: Node.js, Express
  • RAG API: Python, Flask
  • Language Processing: LangChain, FAISS, HuggingFace Embeddings
  • AI Model: Llama3 via Groq API
  • Email Processing: Postmark
  • Process Management: PM2

πŸ” Project Structure

email-ai-assistant/
β”œβ”€β”€ backend/                  # Webhook server and RAG API
β”‚   β”œβ”€β”€ error_emails/         # Stores emails with processing errors
β”‚   β”œβ”€β”€ rag/                  # Retrieval Augmented Generation API
β”‚   β”‚   β”œβ”€β”€ indexador.py      # Document indexing
…

How I Built It

First Steps

I invented β€œVerdeVive”, an Angolan company dedicated to promoting a sustainable lifestyle through ecological and ethical products. I hosted the website on Vercel using a domain I bought from LWS. You can visit the VerdeVive website at this link: Verdevive

I created an instance on AWS: an Ubuntu Server 24.04 on the Free Tier plan, where my RAG system is running, which processes the messages received via Postmark.

Tech Stack βš™οΈ

  • Backend Webhook: Node.js, Express
  • RAG API: Python, Flask
  • Language Processing: LangChain, FAISS, HuggingFace Embeddings
  • AI Model: Llama3 via Groq API
  • Email Processing: Postmark
  • Process Management: PM2

Email Processing:For more technical details, you can access my repository and follow the step-by-step described in the README. Postmark was key here, handling everything from inbound processing and webhooks to final delivery.

Implementation Process πŸ”„

First off, I gathered all of VerdeVive's product documentation to build a solid knowledge base. Then, I vectorized this content using sentence-transformers embeddings. With that ready, I built a Flask API to connect the FAISS index with the Groq LLM.

Next, I implemented the webhook server to process those incoming Postmark emails. Crafting responsive and accessible email templates for the replies was another crucial step. To keep the whole system reliable, I set up PM2 as the process manager. And of course, I put logging and monitoring in place to keep an eye on system health.

Postmark Integration πŸ“¬

For this project, I made full use of several powerful Postmark features:

  • Inbound Stream: Essential for automatically receiving and processing customer questions via email directly into the application.

  • Transactional Stream: Used to send time-sensitive messages such as confirmations and alerts, triggered for one recipient at a time.

  • Webhooks: Enabled real-time processing of every incoming email.

  • Message Streams: This feature helped me clearly separate transactional emails from inbound ones, ensuring maximum deliverability and organization.

πŸ”„ How I Used Message Streams:

Stream Type Direction Purpose
Transactional Outbound Sending time-sensitive automated messages and replies to users (e.g., confirmations, responses)
Inbound Inbound Receiving and parsing emails from customers (e.g., support or contact requests)

πŸ“Š My Activity in the Postmark Server

My activity in the Postmark server


🧾 Parsing Incoming Emails

Below is an example of an incoming email being received and parsed correctly:

Receiving and parsing email

Experience with Postmark ⭐

I didn't know about Postmark until the β€œPostmark Challenge: Inbox Innovators” was published on dev.to. I use Gmail as my email provider, bought a domain that gave me access to a professional email, and signed up on the Postmark website.

On the site, the first thing I saw was the introduction to what a Postmark server is: it works like a β€œfolder”, as simple as that. At first, I didn't really understand what they meant by "folder," but then it became clearer.

Postmark has a wealth of documentation that helped me understand a bit about inbound email parsing. I used the Postmark Help assistant a lot (β€œπŸ‘‹ I'm Stamp, your AI powered assistant”), which provided very practical answers.

Top comments (0)