Quick overview
This workflow monitors a Gmail inbox for unread messages from a specified sender, extracts and cleans the email content, uses an Ollama (Qwen) model to classify sales inquiries in Arabic and draft replies, and automatically replies in Gmail only when a reply draft is produced.
How it works
- Checks the Gmail inbox every minute for unread messages that match the configured sender filter.
- Extracts sender, subject, headers, and body text, cleans the content, and flags basic attributes like attachments and reply/forward status.
- Sends the cleaned email details to an Ollama chat model (qwen3.5:4b) to classify the message as action_required or follow_up and generate an Arabic reply draft when appropriate.
- Parses the model output into structured fields (category and replyDraft) and merges it back with the original Gmail metadata.
- Routes emails by category and continues only for action_required messages.
- Checks that replyDraft is not empty and replies to the original Gmail message with the generated Arabic text.
Setup
- Connect your Gmail account credentials for both the Gmail Trigger and the Gmail reply action, and ensure the connected account is the one that receives and replies to emails.
- In Gmail Trigger → Filters → Search, replace example.invalid with the full email address you will send test messages from. Keep the in:inbox and from: filters in place.
- Install and run Ollama, pull the
qwen3.5:4b model, and set the Ollama Base URL in the Ollama connection so your n8n instance can reach it.
- Connect Ollama Chat Model and Structured Output Parser to the AI Email Classifier, then verify that a test run returns the category and replyDraft fields.
- Test with a sales inquiry and a “thank you” reply to confirm only action_required emails generate a Gmail reply and follow_up messages do not send anything.