{
  "id": "76EjZq8dvntzQ5wu",
  "name": "Smart Email Filtering System (using keywords)",
  "tags": [
    {
      "id": "tA4sFR87A6qRJIoY",
      "name": "Email Filtering",
      "createdAt": "2026-03-05T22:03:32.067Z",
      "updatedAt": "2026-03-05T22:03:32.067Z"
    }
  ],
  "nodes": [
    {
      "id": "03449484-6387-4f40-9af0-c8c0bdf1822e",
      "name": "Extract Email Data",
      "type": "n8n-nodes-base.set",
      "position": [
        -656,
        112
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "email_content",
              "name": "email_content",
              "type": "string",
              "value": "={{ $json.subject + ' ' + $json.text }}"
            },
            {
              "id": "ae4a7020-91b7-4bff-8095-dfc02c84d697",
              "name": "sender_email",
              "type": "string",
              "value": "={{ $json.from.value[0].address }}"
            },
            {
              "id": "a37859f3-0655-4dfc-875f-e6a3587df67a",
              "name": "sender_name",
              "type": "string",
              "value": "={{ $json.from.value[0].name || 'Unknown' }}"
            },
            {
              "id": "message_id",
              "name": "message_id",
              "type": "string",
              "value": "={{ $json.id }}"
            },
            {
              "id": "fcc66569-210c-49ca-a71c-7f4d08c225d9",
              "name": "Subject",
              "type": "string",
              "value": "={{ $json.subject }}"
            }
          ]
        }
      },
      "executeOnce": true,
      "typeVersion": 3.3,
      "alwaysOutputData": true
    },
    {
      "id": "179d0ac6-8492-43e5-834b-cf5c0439a739",
      "name": "Analyze Email Content",
      "type": "n8n-nodes-base.code",
      "position": [
        -448,
        112
      ],
      "parameters": {
        "jsCode": "// TRUSTED DOMAINS - These ALWAYS get classified as legitimate\nconst TRUSTED_DOMAINS = [\n  'stripe.com', 'paypal.com', 'quickbooks.com', 'squareup.com', 'intuit.com',\n  'bill.com', 'plastiq.com', 'xero.com', 'freshbooks.com', 'waveapps.com',\n  'expensify.com', 'bench.co', 'shopify.com', 'amazon.com', 'ebay.com',\n  'etsy.com', 'bigcommerce.com', 'woocommerce.com', 'bankofamerica.com',\n  'chase.com', 'wellsfargo.com', 'usbank.com', 'capitalone.com',\n  'americanexpress.com', 'citibank.com', 'truist.com', 'okta.com',\n  'duosecurity.com', 'authy.com', 'onelogin.com', 'lastpass.com',\n  '1password.com', 'notion.so', 'gusto.com', 'zenefits.com',\n  'justworks.com', 'paychex.com', 'adp.com', 'tri-net.com',\n  'rippling.com', 'ups.com', 'fedex.com', 'usps.com', 'shipstation.com',\n  'easypost.com', 'dropbox.com', 'box.com', 'atlassian.com',\n  'slack.com', 'zoom.us', 'microsoft.com', 'google.com',\n  'docusign.net', 'hellosign.com', 'hubspotusercontent00.net'\n];\n\n// LEGITIMATE INDICATORS - Patterns that suggest legitimate emails\nconst LEGITIMATE_PATTERNS = [\n  'invoice', 'receipt', 'payment', 'billing', 'account',\n  'security alert', 'password', 'verification', 'confirm',\n  'order confirmation', 'shipping', 'delivery', 'support ticket',\n  'customer service', 'help desk', 'technical support'\n];\n\n// Cold outreach detection keywords (existing)\nconst coldKeywords = [\n  'boost your leads', 'white label', 'book a quick call',\n  'partnership opportunity', 'increase your revenue', 'grow your business',\n  'I noticed your website', 'schedule a brief call', 'quick question',\n  'following up', 'lead generation', 'marketing services',\n  'SEO services', 'web design', 'digital marketing', 'outreach',\n  'sales funnel', 'conversion optimization', 'traffic generation',\n  'business development', 'collaboration opportunity', 'mutual benefit',\n  'leverage', 'scale your business', 'competitive advantage',\n  'free consultation', 'free audit', 'free trial', 'no obligation',\n  'proven results', 'case study', 'success story', 'expertise',\n  'transform', 'optimize', 'maximize', 'accelerate', 'streamline'\n];\n\n// Sales tool domains (existing)\nconst salesToolDomains = [\n  'outreach.io', 'salesforce.com', 'hubspot.com', 'mailchimp.com',\n  'apollo.io', 'lemlist.com', 'reply.io', 'salesloft.com',\n  'mixmax.com', 'yesware.com', 'constantcontact.com'\n];\n\n// NEEDS REVIEW INDICATORS - Patterns that suggest AI-generated manipulation\nconst NEEDS_REVIEW_INDICATORS = [\n  // Artificial familiarity patterns\n  'I came across your', 'I noticed your company', 'I saw your recent',\n  'I found your contact', 'I was looking at your', 'I stumbled upon',\n  'caught my attention', 'impressed by your', 'admire your work',\n  \n  // Soft sales with fake personalization\n  'thought you might be interested', 'this might be relevant',\n  'could be valuable for', 'might help with', 'could benefit from',\n  'worth exploring', 'potential fit', 'makes sense for',\n  \n  // Urgency + softness combo\n  'quick favor', 'brief moment', 'short call', 'few minutes',\n  'when you have time', 'at your convenience', 'no pressure',\n  \n  // Generic + specific manipulation\n  'based on your industry', 'companies like yours', 'similar businesses',\n  'your specific needs', 'tailored solution', 'customized approach'\n];\n\n// Get email content and sender\nconst emailContent = $input.first().json.email_content.toLowerCase();\nconst senderEmail = $input.first().json.sender_email.toLowerCase();\nconst senderName = $input.first().json.sender_name || '';\nconst messageId = $input.first().json.message_id;\n\n// Extract domain from sender email\nconst senderDomain = senderEmail.split('@')[1] || '';\n\n// WHITELIST CHECK - Highest priority\nlet isFromTrustedDomain = false;\nfor (const domain of TRUSTED_DOMAINS) {\n  if (senderDomain.includes(domain.toLowerCase())) {\n    isFromTrustedDomain = true;\n    break;\n  }\n}\n\n// If from trusted domain, immediately classify as legitimate\nif (isFromTrustedDomain) {\n  return {\n    json: {\n      message_id: messageId,\n      email_type: 'legitimate',\n      confidence: 95,\n      classification_reason: 'trusted_domain',\n      found_keywords: [],\n      sales_tool_detected: false,\n      has_unsubscribe: false,\n      sender_email: senderEmail,\n      sender_domain: senderDomain,\n      analysis_timestamp: new Date().toISOString()\n    }\n  };\n}\n\n// Check for legitimate patterns\nlet legitimateScore = 0;\nlet foundLegitimatePatterns = [];\nfor (const pattern of LEGITIMATE_PATTERNS) {\n  if (emailContent.includes(pattern.toLowerCase())) {\n    legitimateScore += 15;\n    foundLegitimatePatterns.push(pattern);\n  }\n}\n\n// Check for cold outreach keywords\nlet foundKeywords = [];\nfor (const keyword of coldKeywords) {\n  if (emailContent.includes(keyword.toLowerCase())) {\n    foundKeywords.push(keyword);\n  }\n}\n\n// Check for sales tool domains\nlet salesToolDetected = false;\nfor (const domain of salesToolDomains) {\n  if (senderEmail.includes(domain)) {\n    salesToolDetected = true;\n    break;\n  }\n}\n\n// Check for needs review indicators\nlet reviewScore = 0;\nlet foundReviewIndicators = [];\nfor (const indicator of NEEDS_REVIEW_INDICATORS) {\n  if (emailContent.includes(indicator.toLowerCase())) {\n    reviewScore += 8;\n    foundReviewIndicators.push(indicator);\n  }\n}\n\n// Check for excessive personalization (manipulation tactic)\nconst nameCount = (emailContent.match(new RegExp(senderName.toLowerCase(), 'g')) || []).length;\nif (nameCount >= 3) {\n  reviewScore += 15;\n  foundReviewIndicators.push('excessive_name_usage');\n}\n\n// Check for unsubscribe links (marketing emails)\nconst hasUnsubscribe = emailContent.includes('unsubscribe') || \n                      emailContent.includes('opt out') || \n                      emailContent.includes('remove me') ||\n                      emailContent.includes('manage preferences') ||\n                      emailContent.includes('stop receiving') ||\n                      emailContent.includes('email preferences');\n\n// CLASSIFICATION LOGIC\nlet emailType = 'legitimate';\nlet confidence = legitimateScore;\nlet classificationReason = 'default';\n\n// Marketing emails - Check FIRST after trusted domains\nif (hasUnsubscribe && foundKeywords.length <= 1) {\n  emailType = 'marketing';\n  confidence = 40;\n  classificationReason = 'marketing_unsubscribe';\n}\n// High confidence cold outreach\nelse if (foundKeywords.length >= 2 || salesToolDetected) {\n  emailType = 'cold_outreach';\n  confidence = foundKeywords.length * 10 + (salesToolDetected ? 30 : 0);\n  classificationReason = 'cold_outreach_detected';\n}\n// Needs review - suspicious but not obvious cold outreach\nelse if (reviewScore >= 30 && foundKeywords.length <= 1 && legitimateScore < 15) {\n  emailType = 'needs_review';\n  confidence = reviewScore;\n  classificationReason = 'manipulation_indicators';\n}\n// Legitimate with strong indicators\nelse if (legitimateScore >= 15) {\n  emailType = 'legitimate';\n  confidence = legitimateScore;\n  classificationReason = 'legitimate_patterns';\n}\n// Default to legitimate if no strong indicators either way\nelse {\n  emailType = 'legitimate';\n  confidence = 20;\n  classificationReason = 'default_legitimate';\n}\n\n// Return analysis results\nreturn {\n  json: {\n    message_id: messageId,\n    email_type: emailType,\n    confidence: confidence,\n    classification_reason: classificationReason,\n    found_keywords: foundKeywords,\n    found_legitimate_patterns: foundLegitimatePatterns,\n    found_review_indicators: foundReviewIndicators,\n    sales_tool_detected: salesToolDetected,\n    has_unsubscribe: hasUnsubscribe,\n    sender_email: senderEmail,\n    sender_domain: senderDomain,\n    legitimate_score: legitimateScore,\n    review_score: reviewScore,\n    analysis_timestamp: new Date().toISOString()\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "a1a5a7ed-c90b-4f75-8d1a-3ea78372cc20",
      "name": "Label as Outreach",
      "type": "n8n-nodes-base.gmail",
      "position": [
        0,
        0
      ],
      "parameters": {
        "labelIds": [
          "Label_1684442270786871755"
        ],
        "messageId": "={{ $json.message_id }}",
        "operation": "addLabels"
      },
      "typeVersion": 2
    },
    {
      "id": "bc8a106d-300b-44b7-b8bd-219c9b0bf26c",
      "name": "Remove from Inbox",
      "type": "n8n-nodes-base.gmail",
      "position": [
        224,
        0
      ],
      "parameters": {
        "labelIds": [
          "INBOX"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "removeLabels"
      },
      "typeVersion": 2
    },
    {
      "id": "cacc4443-e5ab-4ff6-96f8-b17283bd711a",
      "name": "Mark as Read",
      "type": "n8n-nodes-base.gmail",
      "position": [
        448,
        0
      ],
      "parameters": {
        "messageId": "={{ $json.id }}",
        "operation": "markAsRead"
      },
      "typeVersion": 2
    },
    {
      "id": "d21174b5-d5c4-44f6-85a4-f6b5b08ca357",
      "name": "Check if Marketing",
      "type": "n8n-nodes-base.if",
      "position": [
        64,
        544
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "marketing_condition",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.email_type }}",
              "rightValue": "marketing"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "c2bc918a-73f4-479e-9f21-a648b8631819",
      "name": "Label as Legitimate",
      "type": "n8n-nodes-base.gmail",
      "position": [
        352,
        720
      ],
      "parameters": {
        "labelIds": [
          "Label_9187111232+1234567890"
        ],
        "messageId": "={{ $json.message_id }}",
        "operation": "addLabels"
      },
      "typeVersion": 2
    },
    {
      "id": "801a1be0-171e-4304-886c-dc8ed2f4f39e",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -1056,
        112
      ],
      "parameters": {
        "filters": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "b0e4bdb8-cb9f-49f9-a2c9-32135c4c7183",
      "name": "Get a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -864,
        112
      ],
      "parameters": {
        "simple": false,
        "options": {},
        "messageId": "={{ $json.id }}",
        "operation": "get"
      },
      "typeVersion": 2.1
    },
    {
      "id": "1e1eb89b-aa0c-4939-ad4f-713059830b29",
      "name": "Check if Needs_review",
      "type": "n8n-nodes-base.if",
      "position": [
        -176,
        368
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "marketing_condition",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.email_type }}",
              "rightValue": "needs_review"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "11c3f86c-03ca-47af-9b85-7e05459eedce",
      "name": "Label as Needs Review",
      "type": "n8n-nodes-base.gmail",
      "position": [
        80,
        304
      ],
      "parameters": {
        "labelIds": [
          "Label_221566828550691632"
        ],
        "messageId": "={{ $json.message_id }}",
        "operation": "addLabels"
      },
      "typeVersion": 2
    },
    {
      "id": "ed1ec15e-5d31-4a00-a463-1fef1245df25",
      "name": "Check If Cold Outreach",
      "type": "n8n-nodes-base.if",
      "position": [
        -224,
        112
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "cold_outreach_condition",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.email_type }}",
              "rightValue": "cold_outreach"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "0fc883f1-ed7b-432d-9aab-7848ad84594b",
      "name": "Edit Fields (outreach)",
      "type": "n8n-nodes-base.set",
      "position": [
        672,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "0e19a6df-4afd-4ee7-8276-00ca6dfd4978",
              "name": "analysis_timestamp",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.analysis_timestamp }}"
            },
            {
              "id": "a88dcad7-9361-4060-a40a-49f061508872",
              "name": "message_id",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.message_id }}"
            },
            {
              "id": "923ed8d5-f75e-4bb4-a2e2-ef96800303ef",
              "name": "sender_email",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.sender_email }}"
            },
            {
              "id": "a300d4e9-d99e-40c7-aa99-60283b1abbe5",
              "name": "sender_name",
              "type": "string",
              "value": "={{ $('Extract Email Data').first().json.sender_name }}"
            },
            {
              "id": "1bbf7f8f-f045-48d8-8c14-972d51076e17",
              "name": "subject",
              "type": "string",
              "value": "={{ $('Extract Email Data').first().json.Subject }}"
            },
            {
              "id": "35da8cf5-11f7-4162-89b8-c51cee6e7d47",
              "name": "email_type",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.email_type }}"
            },
            {
              "id": "96473dbf-f401-40a8-83a3-803ff362ed40",
              "name": "confidence",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.confidence }}"
            },
            {
              "id": "00f80c92-0aa5-4b30-b4e7-d86ca2fd219f",
              "name": "keywords_found",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.found_keywords.join(', ') }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "6f7e573d-0043-4a27-8ee1-0496bbf2f0d7",
      "name": "Edit Fields (needs review)",
      "type": "n8n-nodes-base.set",
      "position": [
        320,
        272
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "0e19a6df-4afd-4ee7-8276-00ca6dfd4978",
              "name": "analysis_timestamp",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.analysis_timestamp }}"
            },
            {
              "id": "a88dcad7-9361-4060-a40a-49f061508872",
              "name": "message_id",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.message_id }}"
            },
            {
              "id": "923ed8d5-f75e-4bb4-a2e2-ef96800303ef",
              "name": "sender_email",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.sender_email }}"
            },
            {
              "id": "a300d4e9-d99e-40c7-aa99-60283b1abbe5",
              "name": "sender_name",
              "type": "string",
              "value": "={{ $('Extract Email Data').first().json.sender_name }}"
            },
            {
              "id": "1bbf7f8f-f045-48d8-8c14-972d51076e17",
              "name": "subject",
              "type": "string",
              "value": "={{ $('Extract Email Data').first().json.Subject }}"
            },
            {
              "id": "35da8cf5-11f7-4162-89b8-c51cee6e7d47",
              "name": "email_type",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.email_type }}"
            },
            {
              "id": "96473dbf-f401-40a8-83a3-803ff362ed40",
              "name": "confidence",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.confidence }}"
            },
            {
              "id": "00f80c92-0aa5-4b30-b4e7-d86ca2fd219f",
              "name": "keywords_found",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.found_keywords.join(', ') }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "d1c83d0c-7eb0-43c5-a860-ebd331d9e3ee",
      "name": "Edit Fields (marketing)",
      "type": "n8n-nodes-base.set",
      "position": [
        624,
        464
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "0e19a6df-4afd-4ee7-8276-00ca6dfd4978",
              "name": "analysis_timestamp",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.analysis_timestamp }}"
            },
            {
              "id": "a88dcad7-9361-4060-a40a-49f061508872",
              "name": "message_id",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.message_id }}"
            },
            {
              "id": "923ed8d5-f75e-4bb4-a2e2-ef96800303ef",
              "name": "sender_email",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.sender_email }}"
            },
            {
              "id": "a300d4e9-d99e-40c7-aa99-60283b1abbe5",
              "name": "sender_name",
              "type": "string",
              "value": "={{ $('Extract Email Data').first().json.sender_name }}"
            },
            {
              "id": "1bbf7f8f-f045-48d8-8c14-972d51076e17",
              "name": "subject",
              "type": "string",
              "value": "={{ $('Extract Email Data').first().json.Subject }}"
            },
            {
              "id": "35da8cf5-11f7-4162-89b8-c51cee6e7d47",
              "name": "email_type",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.email_type }}"
            },
            {
              "id": "96473dbf-f401-40a8-83a3-803ff362ed40",
              "name": "confidence",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.confidence }}"
            },
            {
              "id": "00f80c92-0aa5-4b30-b4e7-d86ca2fd219f",
              "name": "keywords_found",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.found_keywords.join(', ') }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "527fdc6f-c77c-4a3f-9081-fecff667b793",
      "name": "Edit Fields (Legitimate)",
      "type": "n8n-nodes-base.set",
      "position": [
        624,
        720
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "0e19a6df-4afd-4ee7-8276-00ca6dfd4978",
              "name": "analysis_timestamp",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.analysis_timestamp }}"
            },
            {
              "id": "a88dcad7-9361-4060-a40a-49f061508872",
              "name": "message_id",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.message_id }}"
            },
            {
              "id": "923ed8d5-f75e-4bb4-a2e2-ef96800303ef",
              "name": "sender_email",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.sender_email }}"
            },
            {
              "id": "a300d4e9-d99e-40c7-aa99-60283b1abbe5",
              "name": "sender_name",
              "type": "string",
              "value": "={{ $('Extract Email Data').first().json.sender_name }}"
            },
            {
              "id": "1bbf7f8f-f045-48d8-8c14-972d51076e17",
              "name": "subject",
              "type": "string",
              "value": "={{ $('Extract Email Data').first().json.Subject }}"
            },
            {
              "id": "35da8cf5-11f7-4162-89b8-c51cee6e7d47",
              "name": "email_type",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.email_type }}"
            },
            {
              "id": "96473dbf-f401-40a8-83a3-803ff362ed40",
              "name": "confidence",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.confidence }}"
            },
            {
              "id": "00f80c92-0aa5-4b30-b4e7-d86ca2fd219f",
              "name": "keywords_found",
              "type": "string",
              "value": "={{ $('Analyze Email Content').first().json.found_keywords.join(', ') }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "99d3da05-070a-4caa-9403-42f726c87c21",
      "name": "Log to Spreadsheet (outreach)",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        912,
        0
      ],
      "parameters": {
        "columns": {
          "value": {
            "subject": "={{ $json.subject }}",
            "timestamp": "={{ $json.analysis_timestamp }}",
            "confidence": "={{ $json.confidence }}",
            "email_type": "={{ $json.email_type }}",
            "message_id": "={{ $json.message_id }}",
            "sender_name": "={{ $json.sender_name }}",
            "sender_email": "={{ $json.sender_email }}",
            "keywords_found": "={{ $json.keywords_found }}"
          },
          "schema": [
            {
              "id": "timestamp",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "message_id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "message_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "sender_email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "sender_email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "sender_name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "sender_name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "subject",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "subject",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email_type",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "email_type",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "confidence",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "confidence",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "keywords_found",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "keywords_found",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1zGITC9Zm6PFR-5KXFdcVrwafMRbzcX1OL_x3P1tjSqM/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": ""
        }
      },
      "typeVersion": 4
    },
    {
      "id": "57b7a58a-ba34-414d-bc06-19a7c95ffad6",
      "name": "Log to Spreadsheet (needs review)",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        592,
        272
      ],
      "parameters": {
        "columns": {
          "value": {
            "subject": "={{ $json.subject }}",
            "timestamp": "={{ $json.analysis_timestamp }}",
            "confidence": "={{ $json.confidence }}",
            "email_type": "={{ $json.email_type }}",
            "message_id": "={{ $json.message_id }}",
            "sender_name": "={{ $json.sender_name }}",
            "sender_email": "={{ $json.sender_email }}",
            "keywords_found": "={{ $json.keywords_found }}"
          },
          "schema": [
            {
              "id": "timestamp",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "message_id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "message_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "sender_email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "sender_email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "sender_name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "sender_name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "subject",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "subject",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email_type",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "email_type",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "confidence",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "confidence",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "keywords_found",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "keywords_found",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1826282113,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1wWOTOFFXB3xvT5TqV2v75V3T6B_B8uoY29LO5Pma3us/edit#gid=1826282113",
          "cachedResultName": "Needs_review"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": ""
        }
      },
      "typeVersion": 4
    },
    {
      "id": "246b4c41-7b53-4d7e-8f98-9bc4ae495f38",
      "name": "Log to Spreadsheet (legitimate)",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        880,
        720
      ],
      "parameters": {
        "columns": {
          "value": {
            "subject": "={{ $json.subject }}",
            "timestamp": "={{ $json.analysis_timestamp }}",
            "confidence": "={{ $json.confidence }}",
            "email_type": "={{ $json.email_type }}",
            "message_id": "={{ $json.message_id }}",
            "sender_name": "={{ $json.sender_name }}",
            "sender_email": "={{ $json.sender_email }}",
            "keywords_found": "={{ $json.keywords_found }}"
          },
          "schema": [
            {
              "id": "timestamp",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "message_id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "message_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "sender_email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "sender_email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "sender_name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "sender_name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "subject",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "subject",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email_type",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "email_type",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "confidence",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "confidence",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "keywords_found",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "keywords_found",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1381922806,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1wWOTOFFXB3xvT5TqV2v75V3T6B_B8uoY29LO5Pma3us/edit#gid=1381922806",
          "cachedResultName": "Legitimate"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": ""
        }
      },
      "typeVersion": 4
    },
    {
      "id": "943c3f79-eab1-404c-b0a5-dd4445a12406",
      "name": "Log to Spreadsheet (marketing/Ads)",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        880,
        464
      ],
      "parameters": {
        "columns": {
          "value": {
            "subject": "={{ $json.subject }}",
            "timestamp": "={{ $json.analysis_timestamp }}",
            "confidence": "={{ $json.confidence }}",
            "email_type": "={{ $json.email_type }}",
            "message_id": "={{ $json.message_id }}",
            "sender_name": "={{ $json.sender_name }}",
            "sender_email": "={{ $json.sender_email }}",
            "keywords_found": "={{ $json.keywords_found }}"
          },
          "schema": [
            {
              "id": "timestamp",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "message_id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "message_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "sender_email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "sender_email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "sender_name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "sender_name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "subject",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "subject",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email_type",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "email_type",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "confidence",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "confidence",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "keywords_found",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "keywords_found",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 626188348,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1wWOTOFFXB3xvT5TqV2v75V3T6B_B8uoY29LO5Pma3us/edit#gid=626188348",
          "cachedResultName": "Marketing"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": ""
        }
      },
      "typeVersion": 4
    },
    {
      "id": "41d96057-e17e-4327-9454-4c8cbaef6c18",
      "name": "Label as Marketing/Ads",
      "type": "n8n-nodes-base.gmail",
      "position": [
        368,
        464
      ],
      "parameters": {
        "labelIds": [
          "Label_999978575131975706"
        ],
        "messageId": "={{ $json.message_id }}",
        "operation": "addLabels"
      },
      "typeVersion": 2
    },
    {
      "id": "33d7e260-454d-4b28-8b63-c0185c711362",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1328,
        -480
      ],
      "parameters": {
        "color": "#897070",
        "width": 400,
        "height": 832,
        "content": "## Workflow Overview +Gmail Setup\n\nThis workflow automatically filters incoming Gmail emails using keyword detection.\n\nThe workflow analyzes the email subject and snippet to determine whether the email is likely:\n\n\u2022 Cold outreach\n\u2022 Marketing / promotional\n\u2022 Needs manual review\n\u2022 Legitimate communication\n\nBefore running the workflow, create the following Gmail labels:\n\nCold Outreach\nMarketing\nNeeds Review\nLegitimate\n\nYou can create these labels in Gmail by selecting \"Create new label\" in the left sidebar.\n\nThe Gmail trigger node listens for new incoming emails and starts the workflow whenever a message arrives."
      },
      "typeVersion": 1
    },
    {
      "id": "7f900928-7caf-4852-8e0f-e3ffc10b2b02",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -880,
        -432
      ],
      "parameters": {
        "color": "#897070",
        "width": 576,
        "height": 768,
        "content": "## Email Data Extraction and Analyze\n\nThese nodes retrieve the full Gmail message and analyze them.\n\nThe workflow extracts useful fields such as:\n\n\u2022 Sender email\n\u2022 Subject line\n\u2022 Email snippet\n\u2022 Timestamp\n\nThese values are then used in the filtering logic to determine the email category."
      },
      "typeVersion": 1
    },
    {
      "id": "bf5395cc-46e7-4543-bb39-0f5ef4c02722",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -720,
        544
      ],
      "parameters": {
        "color": "#897070",
        "width": 576,
        "height": 400,
        "content": "## Keyword Filtering Logic\n\nThis section checks the email subject and snippet for keywords commonly associated with:\n\nCold outreach:\nsales outreach, partnership opportunity, quick call, growth strategy, etc.\n\nMarketing emails:\nnewsletter, promotion, discount, marketing campaign, etc.\n\nIf the workflow detects these patterns, the email is classified accordingly.\n\nEmails that do not match clear patterns are sent to the \"Needs Review\" category.\n\nYou can customize these keyword lists to better match your inbox."
      },
      "typeVersion": 1
    },
    {
      "id": "815d3736-f471-4d50-a83c-baded65a371f",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1248,
        -96
      ],
      "parameters": {
        "color": "#897070",
        "width": 576,
        "height": 544,
        "content": "##Email Actions and Optional Logging\n\nAfter classification, the workflow applies the appropriate Gmail label.\n\nActions performed:\n\n\u2022 Apply the label (Cold Outreach / Marketing / Needs Review / Legitimate)\n\u2022 Mark the email as read\n\u2022 Optionally remove it from the inbox\n\nOptional: Google Sheets logging\n\nThe workflow can log processed emails to Google Sheets to keep a record of:\n\n\u2022 timestamp\n\u2022 sender\n\u2022 subject\n\u2022 classification\n\nNote: make sure to make a google sheet in advance with those columns.\n\nYou can disable the logging node if you do not need this feature."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "85cf3b39-a9af-4eec-b505-c4cadf0c90a5",
  "connections": {
    "Mark as Read": {
      "main": [
        [
          {
            "node": "Edit Fields (outreach)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get a message": {
      "main": [
        [
          {
            "node": "Extract Email Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Get a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Label as Outreach": {
      "main": [
        [
          {
            "node": "Remove from Inbox",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove from Inbox": {
      "main": [
        [
          {
            "node": "Mark as Read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if Marketing": {
      "main": [
        [
          {
            "node": "Label as Marketing/Ads",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Label as Legitimate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Email Data": {
      "main": [
        [
          {
            "node": "Analyze Email Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Label as Legitimate": {
      "main": [
        [
          {
            "node": "Edit Fields (Legitimate)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze Email Content": {
      "main": [
        [
          {
            "node": "Check If Cold Outreach",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if Needs_review": {
      "main": [
        [
          {
            "node": "Label as Needs Review",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Check if Marketing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Label as Needs Review": {
      "main": [
        [
          {
            "node": "Edit Fields (needs review)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check If Cold Outreach": {
      "main": [
        [
          {
            "node": "Label as Outreach",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Check if Needs_review",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields (outreach)": {
      "main": [
        [
          {
            "node": "Log to Spreadsheet (outreach)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Label as Marketing/Ads": {
      "main": [
        [
          {
            "node": "Edit Fields (marketing)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields (marketing)": {
      "main": [
        [
          {
            "node": "Log to Spreadsheet (marketing/Ads)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields (Legitimate)": {
      "main": [
        [
          {
            "node": "Log to Spreadsheet (legitimate)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields (needs review)": {
      "main": [
        [
          {
            "node": "Log to Spreadsheet (needs review)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}