Back to Catalog

Email management: Auto-delete marketing emails & generate AI replies with Gemini

Raghvendra dixitRaghvendra dixit
536 views
2/3/2026
Official Page

Description

This workflow intelligently scans your inbox, detects whether an email is marketing or genuine, and takes the right action automatically.

Marketing Emails : Deleted instantly and logged in Google Sheets for tracking.

Non-Marketing Emails : Receive a customized, polite reply crafted using AI.

Tracking : Every action (delete/reply) is recorded for auditing and reference.

Accounts & Tools

  • n8n instance (self-hosted or cloud).
  • Google account with:
    • Gmail API access (for reading, deleting, and replying).
    • Google Sheets API access (for logging deleted/replied emails).
  • IMP/SMTP credentials (if using IMAP trigger instead of Gmail API).
  • Google Gemini (PaLM) API key to classify emails and generate replies.

Setup instructions

  • Create a n8N account on cloud or install it locally. follow the quick start guide this
  • Define your trigger point for your workflow as how or when this needs to run. Currently IMAP has been used to detect if any email is received and if so, trigger the workflow
  • Now, we need to setup the google account which allows our workflow to read emails. Follow this guideline to setup gmail account
  • Next step is to add an AI tool which is google gemini here. To set up and use, see this guideline
  • Since AI response is in text, we need a parser tool to read a specific value from text
  • Setup a categorization tool like this
  • Next is to send or delete email and for this, an existing gmail setup is going to work
  • In the last, we need to set a connection for sheet to keep the logs. Adding any sheet to workflow can be seen as google sheet integration

How it work

  • Once any emails is received, IMAP detects and starts the workflow.
  • Now, email is passed to AI model to see if this email is a marketing email or not. Also, is its not a marketing email, it generates a tailored response. Currently, sender, subject and body of email is being scanned and marked as marketing based on model's feedback.
  • Since AI response is in text format, using a formattor to parse it
  • Next step is to read its category as if it is a marketing email
  • Based on email type, there are 2 steps:
    • delete email if it is a marketing email
    • Read the response from previos node and send that as reply
  • Last step is track this activity as which emails is deleted or replied. In terms of structure of sheet, it has 2 tabs deleted emails & replied emails and both have 2 columns
  1. Email ID
  2. subject

Future

  • Use it to categories emails for wider range like job applications, bills, customer supprt and tailor replies for each categories seperately
  • Logging can done in wider sources like databases etc
  • In case if we are logging on sheet, a further enhancements like follow up emails etc can be done

n8n Email Management: Auto-Delete Marketing Emails & Generate AI Replies with Gemini

This n8n workflow automates the process of managing incoming emails, specifically targeting marketing emails for deletion and generating AI-powered replies for other emails using Google Gemini. It helps you maintain a cleaner inbox and respond efficiently.

What it does

  1. Triggers on New Emails: Listens for new emails arriving in a configured IMAP inbox.
  2. Extracts Email Content: Retrieves the subject and body of the incoming email.
  3. Categorizes Emails: Uses a "Switch" node to categorize emails based on specific keywords in their subject or body.
    • Path 1 (Marketing Emails): If the email is identified as a marketing email (e.g., contains "unsubscribe", "promotion", "newsletter"), it proceeds to be deleted.
    • Path 2 (Other Emails): If the email is not a marketing email, it proceeds to generate an AI reply.
  4. Deletes Marketing Emails: For emails categorized as marketing, it uses the Gmail node to delete them, keeping your inbox clutter-free.
  5. Generates AI Replies: For other emails, it sends the email content to Google Gemini to generate a suitable reply.
  6. Saves AI Replies to Google Sheets: The generated AI reply, along with the original email details, is appended to a Google Sheet for record-keeping and review.
  7. Sends AI Reply (Optional/Manual): The workflow is designed to generate the AI reply and save it. Sending the reply back to the sender would require an additional Gmail "Send Email" node, which is not explicitly configured in this JSON but can be easily added.

Prerequisites/Requirements

  • n8n Instance: A running n8n instance.
  • IMAP Account: Access to an IMAP-enabled email account (e.g., Gmail, Outlook, custom server) to trigger the workflow. You'll need to configure IMAP credentials in n8n.
  • Gmail Account: A Gmail account with appropriate permissions configured as an OAuth2 credential in n8n for deleting emails.
  • Google Gemini API Key: An API key for Google Gemini (or a compatible LangChain provider) configured as a credential in n8n for generating AI replies.
  • Google Sheets Account: A Google Sheets account with a designated spreadsheet to store email details and AI-generated replies. You'll need to configure Google Sheets credentials in n8n.

Setup/Usage

  1. Import the workflow: Download the provided JSON and import it into your n8n instance.
  2. Configure Credentials:
    • Email Trigger (IMAP): Set up your IMAP credentials (host, port, username, password) for the email account you want to monitor.
    • Gmail: Configure your Google OAuth2 credentials for Gmail. Ensure it has permissions to delete emails.
    • Google Gemini: Set up your Google Gemini API key credential.
    • Google Sheets: Configure your Google OAuth2 credentials for Google Sheets. Ensure it has permissions to write to your specified sheet.
  3. Configure Nodes:
    • Email Trigger (IMAP): Specify the mailbox to monitor (e.g., "INBOX").
    • Switch: Review and adjust the conditions in the "Switch" node to accurately identify marketing emails based on your criteria (e.g., keywords in subject/body).
    • Gmail (Delete): Ensure this node is configured to delete the correct email identified as marketing.
    • Google Gemini: Configure the prompt for Gemini to generate appropriate email replies. You might want to include details from the incoming email (subject, sender, body) in the prompt.
    • Google Sheets: Specify the Spreadsheet ID and Sheet Name where you want to log the email details and AI replies. Define the columns for mapping the data.
  4. Activate the Workflow: Once all credentials and nodes are configured, activate the workflow. It will start listening for new emails.

Note: The "Sticky Note" and "Edit Fields" nodes are present for workflow documentation and data manipulation respectively. The "Manual Trigger" is for testing purposes.

Related Templates

Generate song lyrics and music from text prompts using OpenAI and Fal.ai Minimax

Spark your creativity instantly in any chatβ€”turn a simple prompt like "heartbreak ballad" into original, full-length lyrics and a professional AI-generated music track, all without leaving your conversation. πŸ“‹ What This Template Does This chat-triggered workflow harnesses AI to generate detailed, genre-matched song lyrics (at least 600 characters) from user messages, then queues them for music synthesis via Fal.ai's minimax-music model. It polls asynchronously until the track is ready, delivering lyrics and audio URL back in chat. Crafts original, structured lyrics with verses, choruses, and bridges using OpenAI Submits to Fal.ai for melody, instrumentation, and vocals aligned to the style Handles long-running generations with smart looping and status checks Returns complete song package (lyrics + audio link) for seamless sharing πŸ”§ Prerequisites n8n account (self-hosted or cloud with chat integration enabled) OpenAI account with API access for GPT models Fal.ai account for AI music generation πŸ”‘ Required Credentials OpenAI API Setup Go to platform.openai.com β†’ API keys (sidebar) Click "Create new secret key" β†’ Name it (e.g., "n8n Songwriter") Copy the key and add to n8n as "OpenAI API" credential type Test by sending a simple chat completion request Fal.ai HTTP Header Auth Setup Sign up at fal.ai β†’ Dashboard β†’ API Keys Generate a new API key β†’ Copy it In n8n, create "HTTP Header Auth" credential: Name="Fal.ai", Header Name="Authorization", Header Value="Key [Your API Key]" Test with a simple GET to their queue endpoint (e.g., /status) βš™οΈ Configuration Steps Import the workflow JSON into your n8n instance Assign OpenAI API credentials to the "OpenAI Chat Model" node Assign Fal.ai HTTP Header Auth to the "Generate Music Track", "Check Generation Status", and "Fetch Final Result" nodes Activate the workflowβ€”chat trigger will appear in your n8n chat interface Test by messaging: "Create an upbeat pop song about road trips" 🎯 Use Cases Content Creators: YouTubers generating custom jingles for videos on the fly, streamlining production from idea to audio export Educators: Music teachers using chat prompts to create era-specific folk tunes for classroom discussions, fostering interactive learning Gift Personalization: Friends crafting anniversary R&B tracks from shared memories via quick chats, delivering emotional audio surprises Artist Brainstorming: Songwriters prototyping hip-hop beats in real-time during sessions, accelerating collaboration and iteration ⚠️ Troubleshooting Invalid JSON from AI Agent: Ensure the system prompt stresses valid JSON; test the agent standalone with a sample query Music Generation Fails (401/403): Verify Fal.ai API key has minimax-music access; check usage quotas in dashboard Status Polling Loops Indefinitely: Bump wait time to 45-60s for complex tracks; inspect fal.ai queue logs for bottlenecks Lyrics Under 600 Characters: Tweak agent prompt to enforce fuller structures like [V1][C][V2][B][C]; verify output length in executions

Daniel NkenchoBy Daniel Nkencho
601

Auto-reply & create Linear tickets from Gmail with GPT-5, gotoHuman & human review

This workflow automatically classifies every new email from your linked mailbox, drafts a personalized reply, and creates Linear tickets for bugs or feature requests. It uses a human-in-the-loop with gotoHuman and continuously improves itself by learning from approved examples. How it works The workflow triggers on every new email from your linked mailbox. Self-learning Email Classifier: an AI model categorizes the email into defined categories (e.g., Bug Report, Feature Request, Sales Opportunity, etc.). It fetches previously approved classification examples from gotoHuman to refine decisions. Self-learning Email Writer: the AI drafts a reply to the email. It learns over time by using previously approved replies from gotoHuman, with per-classification context to tailor tone and style (e.g., different style for sales vs. bug reports). Human Review in gotoHuman: review the classification and the drafted reply. Drafts can be edited or retried. Approved values are used to train the self-learning agents. Send approved Reply: the approved response is sent as a reply to the email thread. Create ticket: if the classification is Bug or Feature Request, a ticket is created by another AI agent in Linear. Human Review in gotoHuman: How to set up Most importantly, install the gotoHuman node before importing this template! (Just add the node to a blank canvas before importing) Set up credentials for gotoHuman, OpenAI, your email provider (e.g. Gmail), and Linear. In gotoHuman, select and create the pre-built review template "Support email agent" or import the ID: 6fzuCJlFYJtlu9mGYcVT. Select this template in the gotoHuman node. In the "gotoHuman: Fetch approved examples" http nodes you need to add your formId. It is the ID of the review template that you just created/imported in gotoHuman. Requirements gotoHuman (human supervision, memory for self-learning) OpenAI (classification, drafting) Gmail or your preferred email provider (for email trigger+replies) Linear (ticketing) How to customize Expand or refine the categories used by the classifier. Update the prompt to reflect your own taxonomy. Filter fetched training data from gotoHuman by reviewer so the writer adapts to their personalized tone and preferences. Add more context to the AI email writer (calendar events, FAQs, product docs) to improve reply quality.

gotoHumanBy gotoHuman
353

Dynamic Hubspot lead routing with GPT-4 and Airtable sales team distribution

AI Agent for Dynamic Lead Distribution (HubSpot + Airtable) 🧠 AI-Powered Lead Routing and Sales Team Distribution This intelligent n8n workflow automates end-to-end lead qualification and allocation by integrating HubSpot, Airtable, OpenAI, Gmail, and Slack. The system ensures that every new lead is instantly analyzed, scored, and routed to the best-fit sales representative β€” all powered by AI logic, sir. --- πŸ’‘ Key Advantages ⚑ Real-Time Lead Routing Automatically assigns new leads from HubSpot to the most relevant sales rep based on region, capacity, and expertise. 🧠 AI Qualification Engine An OpenAI-powered Agent evaluates the lead’s industry, region, and needs to generate a persona summary and routing rationale. πŸ“Š Centralized Tracking in Airtable Every lead is logged and updated in Airtable with AI insights, rep details, and allocation status for full transparency. πŸ’¬ Instant Notifications Slack and Gmail integrations alert the assigned rep immediately with full lead details and AI-generated notes. πŸ” Seamless CRM Sync Updates the original HubSpot record with lead persona, routing info, and timeline notes for audit-ready history, sir. --- βš™οΈ How It Works HubSpot Trigger – Captures a new lead as soon as it’s created in HubSpot. Fetch Contact Data – Retrieves all relevant fields like name, company, and industry. Clean & Format Data – A Code node standardizes and structures the data for consistency. Airtable Record Creation – Logs the lead data into the β€œLeads” table for centralized tracking. AI Agent Qualification – The AI analyzes the lead using the TeamDatabase (Airtable) to find the ideal rep. Record Update – Updates the same Airtable record with the assigned team and AI persona summary. Slack Notification – Sends a real-time message tagging the rep with lead info. Gmail Notification – Sends a personalized handoff email with context and follow-up actions. HubSpot Sync – Updates the original contact in HubSpot with the assignment details and AI rationale, sir. --- πŸ› οΈ Setup Steps Trigger Node: HubSpot β†’ Detect new leads. HubSpot Node: Retrieve complete lead details. Code Node: Clean and normalize data. Airtable Node: Log lead info in the β€œLeads” table. AI Agent Node: Process lead and match with sales team. Slack Node: Notify the designated representative. Gmail Node: Email the rep with details. HubSpot Node: Update CRM with AI summary and allocation status, sir. --- πŸ” Credentials Required HubSpot OAuth2 API – To fetch and update leads. Airtable Personal Access Token – To store and update lead data. OpenAI API – To power the AI qualification and matching logic. Slack OAuth2 – For sending team notifications. Gmail OAuth2 – For automatic email alerts to assigned reps, sir. --- πŸ‘€ Ideal For Sales Operations and RevOps teams managing multiple regions B2B SaaS and enterprise teams handling large lead volumes Marketing teams requiring AI-driven, bias-free lead assignment Organizations optimizing CRM efficiency with automation, sir --- πŸ’¬ Bonus Tip You can easily extend this workflow by adding lead scoring logic, language translation for follow-ups, or Salesforce integration. The entire system is modular β€” perfect for scaling across global sales teams, sir.

MANISH KUMARBy MANISH KUMAR
113