Automatische Klassifizierung und Markierung von E-Mails in Gmail basierend auf OpenAI GPT-4

Fortgeschritten

Dies ist ein AI Summarization, Multimodal AI-Bereich Automatisierungsworkflow mit 15 Nodes. Hauptsächlich werden Gmail, SplitInBatches, ScheduleTrigger, LmChatOpenAi, TextClassifier und andere Nodes verwendet. Automatische Klassifizierung und Markierung von Gmail-E-Mails basierend auf OpenAI GPT-4

Voraussetzungen
  • Google-Konto + Gmail API-Anmeldedaten
  • OpenAI API Key
Workflow-Vorschau
Visualisierung der Node-Verbindungen, mit Zoom und Pan
Workflow exportieren
Kopieren Sie die folgende JSON-Konfiguration und importieren Sie sie in n8n
{
  "meta": {
    "instanceId": "d1786ab0d745a7498abf13a9c2cdabb1374c006e889b79eef64ce0386b8f8a41",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "434e0315-d478-4fc6-9d68-b6d83692d56d",
      "name": "Zeitplan-Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -220,
        -60
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "9a3551be-1e97-4b1a-986e-55adb27ea660",
      "name": "Elemente durchlaufen",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        220,
        -40
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "e44d7114-2e55-4bc3-82d6-b9fdf10651d8",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        440,
        180
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5",
          "cachedResultName": "gpt-5"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "MGwGMKEkdcjzlYCw",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "123cb1eb-0d71-4e61-a4af-f514c54f20e2",
      "name": "Label hinzufügen (Hohe Priorität)",
      "type": "n8n-nodes-base.gmail",
      "position": [
        940,
        -200
      ],
      "webhookId": "78527ed1-4494-4a9a-994b-a417a3c45ac1",
      "parameters": {
        "labelIds": [
          "IMPORTANT"
        ],
        "resource": "thread",
        "threadId": "={{ $json.threadId }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "CeBpTZBQSAMKVKJY",
          "name": "Gmail account (Billy Email 2)"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "e1b53e1d-da8d-483d-8fe3-ddc821b66c0e",
      "name": "Label hinzufügen (Persönlich)",
      "type": "n8n-nodes-base.gmail",
      "position": [
        940,
        0
      ],
      "webhookId": "78527ed1-4494-4a9a-994b-a417a3c45ac1",
      "parameters": {
        "labelIds": [
          "CATEGORY_PERSONAL"
        ],
        "resource": "thread",
        "threadId": "={{ $json.threadId }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "CeBpTZBQSAMKVKJY",
          "name": "Gmail account (Billy Email 2)"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "711c5194-4046-42ac-8e2e-acbe2026ac29",
      "name": "Label hinzufügen (Werbung)",
      "type": "n8n-nodes-base.gmail",
      "position": [
        940,
        220
      ],
      "webhookId": "78527ed1-4494-4a9a-994b-a417a3c45ac1",
      "parameters": {
        "labelIds": [
          "CATEGORY_PROMOTIONS"
        ],
        "resource": "thread",
        "threadId": "={{ $json.threadId }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "CeBpTZBQSAMKVKJY",
          "name": "Gmail account (Billy Email 2)"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "ac4c736c-4948-4463-9651-54e1b5e592fa",
      "name": "Notiz",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -680,
        -140
      ],
      "parameters": {
        "color": 4,
        "width": 400,
        "height": 300,
        "content": "## SETUP REQUIRED\n\nWorkflow Configurations:\n- Update the Text Classifier and adjust the labels based on your use case.\n- Add/Remove the Gmail addLabels node to match your use case.\n\nRequired Credentials:\n- Gmail Credential\n- OpenAI API Key"
      },
      "typeVersion": 1
    },
    {
      "id": "29a5312e-4ddf-41e7-afff-1e8683feca28",
      "name": "Notiz1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -680,
        500
      ],
      "parameters": {
        "color": 4,
        "width": 680,
        "height": 400,
        "content": "## 📋 WORKFLOW PROCESS OVERVIEW\n\nStep 1: ⏰ Schedule Trigger executes the workflow every 5 minutes automatically\nStep 2: 📨 Gmail Fetch retrieves up to 10 recent emails from the last 5 minutes using Gmail API\nStep 3: 🔄 Loop Over Items processes each email individually through a batch splitting mechanism\nStep 4: 🤖 Text Classifier (AI Agent) analyzes email subject and body content using OpenAI to categorize emails\nStep 5: 🏷️ Add Labels applies the appropriate Gmail label based on classification: (below is an example only, adjust to your own use case)\n  - High Priority emails → \"IMPORTANT\" label\n  - Personal emails → \"CATEGORY_PERSONAL\" label  \n  - Promotional emails → \"CATEGORY_PROMOTIONS\" label\n\n\nStep 6: ↩️ Loop Back continues processing remaining emails until all are classified and labeled"
      },
      "typeVersion": 1
    },
    {
      "id": "8825d969-1365-4c33-bc00-e995deb40e64",
      "name": "Notiz2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -680,
        200
      ],
      "parameters": {
        "color": 4,
        "width": 680,
        "height": 280,
        "content": "## 📧 Smart Gmail Labeling Automation with Text Classifier and GPT-5\n\nWhat This Template Does:\n\n- Runs every 5 minutes to automatically fetch recent emails from your Gmail inbox\n- Retrieves up to 10 emails received within the last 5 minutes\n- Uses OpenAI's Model to intelligently classify each email into predefined categories\n- Automatically applies appropriate Gmail labels based on AI classification results\n- Organizes your inbox by categorizing emails as High Priority, Personal, or Promotional content\n- Processes emails individually through a batch loop to ensure accurate classification"
      },
      "typeVersion": 1
    },
    {
      "id": "6ab81542-c082-409a-affd-138e766d42a9",
      "name": "Notiz4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        860,
        -380
      ],
      "parameters": {
        "color": 4,
        "width": 280,
        "height": 860,
        "content": "## Add Label Nodes\n\nAdd Label Nodes based on your use case. For example, if you have 5 labels, then you can add 5 nodes and adjust the label names on each node.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "e6ef7d72-00a6-457d-8059-f20dcecc9d9f",
      "name": "Notiz5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        440,
        -180
      ],
      "parameters": {
        "color": 4,
        "width": 320,
        "height": 320,
        "content": "## Label Classifier\n\nAdjust the categories based on your use case. Also, add a description to each category for maximum results.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "ce7c17d4-958e-4d77-8b99-07d71b1005a0",
      "name": "Label-Klassifikator",
      "type": "@n8n/n8n-nodes-langchain.textClassifier",
      "position": [
        460,
        0
      ],
      "parameters": {
        "options": {
          "fallback": "other"
        },
        "inputText": "=Email Subject:\n{{ $json.headers.subject }}\n\nEmail Body:\n{{ $json.text }}",
        "categories": {
          "categories": [
            {
              "category": "High Priority",
              "description": "Emails that require immediate attention or urgent action."
            },
            {
              "category": "Personal",
              "description": "Personal refers to activities or matters related to private life, self, or non-work interests."
            },
            {
              "category": "Promotions",
              "description": "Promotions refer to marketing messages or activities that advertise products, services, or offers"
            }
          ]
        }
      },
      "typeVersion": 1,
      "alwaysOutputData": false
    },
    {
      "id": "1c81d787-784f-48bb-bdd2-2b9b2f9fc975",
      "name": "Notiz6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -120,
        -220
      ],
      "parameters": {
        "color": 4,
        "width": 320,
        "height": 320,
        "content": "## Gmail - Get Emails\n\nGet all messages received within the last 5 minutes.  \nYou can adjust the time range and the email limit here.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "9482f1e2-d564-4f15-938e-d4db4b1a59cb",
      "name": "Gmail - E-Mails abrufen",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -20,
        -60
      ],
      "webhookId": "9777ca5f-5226-4fc8-b93b-a3344f890dd3",
      "parameters": {
        "limit": 10,
        "simple": false,
        "filters": {
          "receivedAfter": "={{ $now.minus({ minutes: 50000 }).toMillis() }}"
        },
        "options": {},
        "operation": "getAll"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "CeBpTZBQSAMKVKJY",
          "name": "Gmail account (Billy Email 2)"
        }
      },
      "typeVersion": 2.1
    }
  ],
  "pinData": {},
  "connections": {
    "9a3551be-1e97-4b1a-986e-55adb27ea660": {
      "main": [
        [],
        [
          {
            "node": "ce7c17d4-958e-4d77-8b99-07d71b1005a0",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ce7c17d4-958e-4d77-8b99-07d71b1005a0": {
      "main": [
        [
          {
            "node": "123cb1eb-0d71-4e61-a4af-f514c54f20e2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "e1b53e1d-da8d-483d-8fe3-ddc821b66c0e",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "711c5194-4046-42ac-8e2e-acbe2026ac29",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "9a3551be-1e97-4b1a-986e-55adb27ea660",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "434e0315-d478-4fc6-9d68-b6d83692d56d": {
      "main": [
        [
          {
            "node": "9482f1e2-d564-4f15-938e-d4db4b1a59cb",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "e44d7114-2e55-4bc3-82d6-b9fdf10651d8": {
      "ai_languageModel": [
        [
          {
            "node": "ce7c17d4-958e-4d77-8b99-07d71b1005a0",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "9482f1e2-d564-4f15-938e-d4db4b1a59cb": {
      "main": [
        [
          {
            "node": "9a3551be-1e97-4b1a-986e-55adb27ea660",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "e1b53e1d-da8d-483d-8fe3-ddc821b66c0e": {
      "main": [
        [
          {
            "node": "9a3551be-1e97-4b1a-986e-55adb27ea660",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "711c5194-4046-42ac-8e2e-acbe2026ac29": {
      "main": [
        [
          {
            "node": "9a3551be-1e97-4b1a-986e-55adb27ea660",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "123cb1eb-0d71-4e61-a4af-f514c54f20e2": {
      "main": [
        [
          {
            "node": "9a3551be-1e97-4b1a-986e-55adb27ea660",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Häufig gestellte Fragen

Wie verwende ich diesen Workflow?

Kopieren Sie den obigen JSON-Code, erstellen Sie einen neuen Workflow in Ihrer n8n-Instanz und wählen Sie "Aus JSON importieren". Fügen Sie die Konfiguration ein und passen Sie die Anmeldedaten nach Bedarf an.

Für welche Szenarien ist dieser Workflow geeignet?

Fortgeschritten - KI-Zusammenfassung, Multimodales KI

Ist es kostenpflichtig?

Dieser Workflow ist völlig kostenlos. Beachten Sie jedoch, dass Drittanbieterdienste (wie OpenAI API), die im Workflow verwendet werden, möglicherweise kostenpflichtig sind.

Workflow-Informationen
Schwierigkeitsgrad
Fortgeschritten
Anzahl der Nodes15
Kategorie2
Node-Typen6
Schwierigkeitsbeschreibung

Für erfahrene Benutzer, mittelkomplexe Workflows mit 6-15 Nodes

Autor
Billy Christi

Billy Christi

@billy

I build scalable automation systems with n8n to help businesses save time and cut costs. 💼 n8n expert available for new projects 📩 billychartanto@gmail.com

Externe Links
Auf n8n.io ansehen

Diesen Workflow teilen

Kategorien

Kategorien: 34