Skip to main content

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

Workflow preview

Workflow preview
100%
Email management: Auto-delete marketing emails & generate AI replies with Gemini preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

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...

Best for

  • Ticket Management automation workflows
  • AI Summarization automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.gmail, n8n-nodes-base.googlesheets, n8n-nodes-base.manualtrigger, n8n-nodes-base.emailreadimap, n8n-nodes-base.stickynote, @n8n/n8n-nodes-langchain.googlegemini, n8n-nodes-base.set, n8n-nodes-base.switch

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Raghvendra dixit.

Original n8n.io source

1.1 Workflow description

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

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

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Delete a message

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 2 - Reply to a message

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 3 - Get many messages

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 4 - Append or update row in sheet

Type / Role
n8n-nodes-base.googleSheets - googleSheets
Config choices
Version 4.6

Block 5 - Append or update row in sheet1

Type / Role
n8n-nodes-base.googleSheets - googleSheets
Config choices
Version 4.6

Block 6 - When clicking ‘Execute workflow’

Type / Role
n8n-nodes-base.manualTrigger - manualTrigger
Config choices
Version 1

Block 7 - Email Trigger (IMAP)

Type / Role
n8n-nodes-base.emailReadImap - emailReadImap
Config choices
Version 2.1

Block 8 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 9 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 10 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 11 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 12 - Message a model

Type / Role
@n8n/n8n-nodes-langchain.googleGemini - googleGemini
Config choices
Version 1

Block 13 - Sticky Note4

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 14 - AI response formatter

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 15 - categories emails

Type / Role
n8n-nodes-base.switch - switch
Config choices
Version 3.2

3. Summary Table

Workflow Email management: Auto-delete marketing emails & generate AI replies with Gemini
Complexity advanced
Nodes 15
Categories Ticket Management, AI Summarization
Author Raghvendra dixit
Published 18 Aug 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/7551/7551.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Email management: Auto-delete marketing emails & generate AI replies with Gemini do?

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...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Ticket Management, AI Summarization use case.