See llms.txt for all machine-readable content.

Back to Templates

Triage and route inbound emails using OpenAI, Slack, Gmail, and Google Sheets

Last update

Last update 21 hours ago

Categories

Share


Quick overview

This workflow polls an IMAP inbox, uses OpenAI to classify each email by urgency, and then routes it to Slack, Google Sheets, Google Drive, or Gmail based on category and confidence, while logging every decision to a Google Sheets audit log.

How it works

  1. Polls an IMAP mailbox every minute for new emails.
  2. Sends the email subject and plain-text body to OpenAI (gpt-4o-mini) to return a JSON classification with category, confidence, and reason.
  3. Posts low-confidence classifications (confidence < 0.7) to a Slack channel for human review.
  4. Routes high-confidence emails by category into urgent, invoice, or routine paths.
  5. Posts urgent emails to a Slack #ops-alerts channel with the sender and the model’s reason.
  6. Uploads invoice attachments to Google Drive and appends the email data to an Invoices sheet in Google Sheets.
  7. Adds a Gmail label to routine emails and appends all outcomes to a DecisionLog sheet in Google Sheets.

Setup

  1. Configure the IMAP connection in the Email Trigger to monitor your target mailbox.
  2. Add an OpenAI API credential (or n8n OpenAI/LangChain credential) for the classification step.
  3. Add Slack credentials and set (or create) the #triage-review and #ops-alerts channels used for notifications.
  4. Add Google Drive credentials and confirm the upload location and filename format for saved invoice attachments.
  5. Add Google Sheets credentials and replace YOUR_LEDGER_SHEET_ID and YOUR_AUDIT_SHEET_ID with your spreadsheet IDs, ensuring the Invoices and DecisionLog tabs exist.
  6. Add Gmail credentials and update the label ID (Label_routine) to a label that exists in your Gmail account.