AutomationFlowsEmail & Gmail › Email Management: Auto-delete Marketing Emails & Generate AI Replies with Gemini

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

ByRaghvendra dixit @raghav on n8n.io

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

Event trigger★★★★☆ complexityAI-powered15 nodesGmailGoogle SheetsEmail Read ImapGoogle Gemini
Email & Gmail Trigger: Event Nodes: 15 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #7551 — we link there as the canonical source.

This workflow follows the Gmail → Googlegemini recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "7GdNKqJiBikANlfc",
  "name": "Wispering-inbox",
  "tags": [],
  "nodes": [
    {
      "id": "804be255-fa04-4da2-ade7-720815a54719",
      "name": "Delete a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        480,
        272
      ],
      "parameters": {
        "messageId": "={{ $json.content.parts[0].text.id }}",
        "operation": "delete"
      },
      "typeVersion": 2.1
    },
    {
      "id": "168d8523-8167-4365-8f86-3114f48f0887",
      "name": "Reply to a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        480,
        464
      ],
      "parameters": {
        "message": "= {{ $json.content.parts[0].text.replyMessage }}",
        "options": {},
        "messageId": "={{ $json.content.parts[0].text.id }}",
        "operation": "reply"
      },
      "typeVersion": 2.1
    },
    {
      "id": "12a25055-b776-4203-a65e-2adc405b6187",
      "name": "Get many messages",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -592,
        272
      ],
      "parameters": {
        "limit": 2,
        "filters": {},
        "operation": "getAll"
      },
      "typeVersion": 2.1
    },
    {
      "id": "7b4c77aa-0d4d-4f94-89f2-c546a689a8c8",
      "name": "Append or update row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        752,
        528
      ],
      "parameters": {
        "columns": {
          "value": {
            "subject": "={{ $('Get many messages').item.json.Subject }}",
            "email id": "={{ $('Get many messages').item.json.From }}"
          },
          "schema": [
            {
              "id": "email id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "email id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "subject",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "subject",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "email id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1EsLx3e71u3YIboqIlc7pUM81YJAjNuhMSqv7kgyGkzw/edit#gid=0",
          "cachedResultName": "deleted emails"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1EsLx3e71u3YIboqIlc7pUM81YJAjNuhMSqv7kgyGkzw",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1EsLx3e71u3YIboqIlc7pUM81YJAjNuhMSqv7kgyGkzw/edit?usp=drivesdk",
          "cachedResultName": "email list"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "c4a2506f-c0eb-4e0c-9187-c256c104f596",
      "name": "Append or update row in sheet1",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        912,
        384
      ],
      "parameters": {
        "columns": {
          "value": {
            "subject": "={{ $('Get many messages').item.json.Subject }}",
            "email id": "={{ $('Get many messages').item.json.From }}"
          },
          "schema": [
            {
              "id": "email id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "email id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "subject",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "subject",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "email id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1619439968,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1EsLx3e71u3YIboqIlc7pUM81YJAjNuhMSqv7kgyGkzw/edit#gid=1619439968",
          "cachedResultName": "replied email"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1EsLx3e71u3YIboqIlc7pUM81YJAjNuhMSqv7kgyGkzw",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1EsLx3e71u3YIboqIlc7pUM81YJAjNuhMSqv7kgyGkzw/edit?usp=drivesdk",
          "cachedResultName": "email list"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "60b53d94-5748-486a-a559-e70f4e125756",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -816,
        272
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "27d393ea-46fc-4d25-828f-440043864122",
      "name": "Email Trigger (IMAP)",
      "type": "n8n-nodes-base.emailReadImap",
      "position": [
        -672,
        592
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 2.1
    },
    {
      "id": "7b65f16d-3908-4b04-a151-65eef73d7c95",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -416,
        16
      ],
      "parameters": {
        "color": 3,
        "width": 400,
        "height": 448,
        "content": "# \ud83d\ude80 Gemini Model Tasks\n## \ud83d\udccc Objectives:\n\n- \ud83d\udd75\ufe0f\u200d\u2642\ufe0f Detect if an incoming email is a marketing email\n\n- \ud83c\udff7\ufe0f If yes \u2192 Add a classification flag like isMarketing: true \u2705\n\n- \u2709\ufe0f If not a marketing email \u2192 Prepare a customized response for clients \ud83e\udd1d"
      },
      "typeVersion": 1
    },
    {
      "id": "7cbe344e-e0b7-4e77-9878-42ac28240de6",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -992,
        464
      ],
      "parameters": {
        "width": 544,
        "height": 224,
        "content": "# \u23f0 Scheduled Trigger\n\u26a1 Instantly kicks off the workflow whenever a new \ud83d\udce9 email lands in the account \u2013 no delays, fully automated! \ud83e\udd16\u2728"
      },
      "typeVersion": 1
    },
    {
      "id": "5a0d1cc4-e3f3-474c-91e8-d8d817c3e434",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "color": 5,
        "width": 448,
        "height": 464,
        "content": "# \ud83c\udff7\ufe0f Classification of Emails\n\n### \ud83d\udccc Based on the feature flag present in the response, this node decides whether the email should be:\n\n\u2709\ufe0f Replied to \u2192 Sent to the Reply Workflow \ud83d\udd01\n\n\ud83d\uddd1\ufe0f Deleted \u2192 Sent to the Delete Workflow \u274c\n\n\ud83e\udd16 Smart decision-making to route emails efficiently!"
      },
      "typeVersion": 1
    },
    {
      "id": "526fe4b0-c5d5-4722-8f2a-50dc312da798",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        608,
        32
      ],
      "parameters": {
        "color": 6,
        "width": 496,
        "height": 688,
        "content": "# \ud83d\udcca Tracking\n\n## \ud83d\uded1 This is the final step of the workflow where all actioned emails are recorded.\n\ud83d\uddc2\ufe0f It keeps track of:\n\n\ud83d\uddd1\ufe0f Deleted emails\n\n\u2709\ufe0f Replied emails, along with their \ud83d\udccc email subjects\n\n\ud83d\udd0d Useful for monitoring, auditing, and future reference!"
      },
      "typeVersion": 1
    },
    {
      "id": "f412f452-5f84-49e6-b0a6-d3e06ab1600d",
      "name": "Message a model",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        -368,
        368
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-flash",
          "cachedResultName": "models/gemini-2.5-flash"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=Take below inputs and validate is it is marketing email\n {{ $json.Subject }}\n{{ $json.From }}\n{{ $json.snippet }}\n\nAdd below nodes in body\nid: {{ $json.id }},\nsubject: {{ $json.Subject }} \nfrom:{{ $json.From }} \n\nalso add isMarketing flag and make it true or false if this a marketing email or not respectively\n\nIncase if it is not a marketing email, I need to reply back to the sender and so create a custom and a respectable reply message and add this reply as new field in response"
            }
          ]
        },
        "jsonOutput": true
      },
      "typeVersion": 1
    },
    {
      "id": "cbb4bf93-536b-47ea-852d-2dfd4fbe24a5",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -992,
        160
      ],
      "parameters": {
        "color": 4,
        "width": 560,
        "height": 256,
        "content": "# \ud83d\udd90\ufe0f Manual Trigger\n\u26a1 Triggered based on user actions \u2013 the workflow starts when the user decides to take action \ud83e\udde0\ud83d\udd79\ufe0f"
      },
      "typeVersion": 1
    },
    {
      "id": "e814bd89-2f16-47f4-8765-2daa40d728cb",
      "name": "AI response formatter",
      "type": "n8n-nodes-base.set",
      "position": [
        32,
        368
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "081fa2a3-91eb-40f5-845f-1ca1d24fb941",
              "name": "content.parts[0].text",
              "type": "object",
              "value": "={{ $json.content.parts[0].text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "2ebd1e06-a096-4283-bfb9-d9cf260c3441",
      "name": "categories emails",
      "type": "n8n-nodes-base.switch",
      "position": [
        256,
        368
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "91c407cc-3862-42f7-a04a-939c05445b6d",
                    "operator": {
                      "type": "boolean",
                      "operation": "true",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.content.parts[0].text.isMarketing }}",
                    "rightValue": "\"isMarketing\": false"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "f0a5e7c2-dd98-4c58-a582-888245c42d35",
                    "operator": {
                      "type": "boolean",
                      "operation": "false",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.content.parts[0].text.isMarketing }}",
                    "rightValue": "\"isMarketing\": false"
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "4c1f5e42-9646-4198-af08-91a62c8bbc93",
  "connections": {
    "Message a model": {
      "main": [
        [
          {
            "node": "AI response formatter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete a message": {
      "main": [
        [
          {
            "node": "Append or update row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get many messages": {
      "main": [
        [
          {
            "node": "Message a model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "categories emails": {
      "main": [
        [
          {
            "node": "Delete a message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Reply to a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reply to a message": {
      "main": [
        [
          {
            "node": "Append or update row in sheet1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email Trigger (IMAP)": {
      "main": [
        [
          {
            "node": "Message a model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI response formatter": {
      "main": [
        [
          {
            "node": "categories emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Get many messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

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

Source: https://n8n.io/workflows/7551/ — original creator credit. Request a take-down →

More Email & Gmail workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

Email & Gmail

This workflow automatically classifies and routes incoming Outlook emails into smart categories using n8n + OpenAI GPT-4.1-mini. It helps professionals and teams stay organized by intelligently sortin

Google Sheets, Gmail, Microsoft Outlook Trigger +3
Email & Gmail

Transform your Google Form into an intelligent customer support system that automatically analyzes, prioritizes, and responds to every inquiry with AI-powered personalization.

Google Sheets Trigger, OpenAI, Gmail +2
Email & Gmail

Alrouf AI Integration (Production). Uses googleSheets, chainLlm, lmChatGoogleGemini, outputParserStructured. Manual trigger; 21 nodes.

Google Sheets, Chain Llm, Google Gemini Chat +5
Email & Gmail

2025-12-03 fix JS code in node

Gmail, Home Assistant, Gmail Trigger +1
Email & Gmail

Stop losing valuable leads to missed meetings with this No-Show Follow-Up & Rescheduling automation! Whenever a lead is marked as a “no-show” in your CRM or calendar, this workflow automatically sends

Google Calendar, Gmail, Google Sheets