Intelligent Mail Classifier
Intelligent automation system that uses the Gemini model to analyze the content of incoming emails and automatically categorize them. Through natural language processing, eYour Business Conversations.
graph TD
%%{init: {'theme': 'mc','layout': 'elk'}}%%
GmailMesageComponent-hy2ma[<div><img alt="logo" src="/_astro/gmail.CLxyIGOu.svg" style="height: 20px !important;width: 20px !important"/></div>Gmail Message]
style GmailMesageComponent-hy2ma stroke:#a170ff
GoogleGenerativeAIModel-vgbbh[Gemini]
style GoogleGenerativeAIModel-vgbbh stroke:#a170ff
GmailMesageComponent-b2dd1[<div><img alt="logo" src="/_astro/gmail.CLxyIGOu.svg" style="height: 20px !important;width: 20px !important"/></div>VENTA]
style GmailMesageComponent-b2dd1 stroke:#a170ff
Prompt-yx16c[<div><img alt="logo" src="/_astro/square-terminal.BMOXc-nZ.svg" style="height: 20px !important;width: 20px !important"/></div>Prompt]
style Prompt-yx16c stroke:#a170ff
Switch-ml52o[Switch]
style Switch-ml52o stroke:#a170ff
GmailMesageComponent-dzaho[<div><img alt="logo" src="/_astro/gmail.CLxyIGOu.svg" style="height: 20px !important;width: 20px !important"/></div>IMPORTANTE]
style GmailMesageComponent-dzaho stroke:#a170ff
GmailMesageComponent-gsepm[<div><img alt="logo" src="/_astro/gmail.CLxyIGOu.svg" style="height: 20px !important;width: 20px !important"/></div>URGENTE]
style GmailMesageComponent-gsepm stroke:#a170ff
GmailMesageComponent-imh3h[<div><img alt="logo" src="/_astro/gmail.CLxyIGOu.svg" style="height: 20px !important;width: 20px !important"/></div>NORMAL]
style GmailMesageComponent-imh3h stroke:#a170ff
CreateData-j2wcd[Create Data]
style CreateData-j2wcd stroke:#a170ff
Prompt-yx16c -.- GoogleGenerativeAIModel-vgbbh
linkStyle 0 stroke:#a170ff
Switch-ml52o -.- GmailMesageComponent-dzaho
linkStyle 1 stroke:#a170ff
Switch-ml52o -.- GmailMesageComponent-gsepm
linkStyle 2 stroke:#a170ff
Switch-ml52o -.- GmailMesageComponent-imh3h
linkStyle 3 stroke:#a170ff
GoogleGenerativeAIModel-vgbbh -.- CreateData-j2wcd
linkStyle 4 stroke:#a170ff
CreateData-j2wcd -.- Switch-ml52o
linkStyle 5 stroke:#a170ff
Switch-ml52o -.- GmailMesageComponent-b2dd1
linkStyle 6 stroke:#a170ff
GmailMesageComponent-hy2ma -.- Prompt-yx16c
linkStyle 7 stroke:#a170ff
🧩 Overview
The Intelligent Mail Classifier automates the categorisation of incoming Gmail messages.
It retrieves unlabelled emails, applies the Gemini language model to classify each message into one of four business‑relevant categories, and then automatically applies the corresponding Gmail label.
This streamlines email triage, ensuring important, urgent, sales, or routine messages are immediately sorted for the user.
⚙️ Main Features
- Retrieves all Gmail messages that lack the ETIQUETADO label once a day.
- Uses a prompt‑based Gemini model to determine the appropriate category for each email.
- Generates a data record containing the label and email ID for downstream processing.
- Routes each record to the correct label‑updating step via a switcher.
- Automatically updates the Gmail label of each message (VENTA, IMPORTANTE, URGENTE, NORMAL) and applies the ETIQUETADO label to mark it as processed.
🔄 Workflow Steps
| Component Name | Role in the Workflow | Key Inputs | Key Outputs |
|---|---|---|---|
| Gmail Message | Fetches all unread Gmail messages that are not labelled ETIQUETADO. | Email query (-label:ETIQUETADO), number of emails to read. |
Raw email data (body, ID). |
| Prompt | Builds a prompt template that instructs Gemini to classify the email content. | Email body. | Prompt text for the model. |
| Gemini | Generates a single‑word classification label (URGENTE, IMPORTANTE, VENTA, or NORMAL). |
Prompt text. | Classified label. |
| Create Data | Creates a structured record with the label (etiqueta) and the original email ID (id). |
Classified label, email ID. | Data record containing {etiqueta, id}. |
| Switch | Routes each record to the appropriate branch based on the etiqueta value. |
Data record. | One of four case outputs (case_1_output–case_4_output). |
| Gmail Message (VENTA) | Adds the VENTA label and the ETIQUETADO label to the email. | Email ID, labels to add. | Updated email. |
| Gmail Message (IMPORTANTE) | Adds the IMPORTANTE label and the ETIQUETADO label to the email. | Email ID, labels to add. | Updated email. |
| Gmail Message (URGENTE) | Adds the URGENTE label and the ETIQUETADO label to the email. | Email ID, labels to add. | Updated email. |
| Gmail Message (NORMAL) | Adds the NORMAL label and the ETIQUETADO label to the email. | Email ID, labels to add. | Updated email. |
🧠 Notes
- The workflow runs automatically once a day, retrieving only messages that have not yet been processed.
- The Gemini model is configured with a strict prompt that requires the model to output only one of the four category keywords, ensuring deterministic routing.
- The Switch component implements a priority order (URGENTE > IMPORTANTE > VENTA > NORMAL) if a message could match multiple categories, preventing duplicate routing.
- Each label‑updating step updates the email’s metadata in Gmail and also adds the ETIQUETADO label, providing a clear audit trail that the email has been classified.
- The system supports batch processing; each component can operate on a list of emails concurrently, limited to a maximum of five parallel executions.
- Error handling is implicit: if a step outputs an empty or
Nonevalue, the downstream components are skipped to avoid cascading failures. - The workflow relies on valid Google API credentials and the Gemini API key; these are stored securely in the platform’s credential store.