OpenAI GPT-4によるGmailメールの自動分類とマーキング

中級

これはAI Summarization, Multimodal AI分野の自動化ワークフローで、15個のノードを含みます。主にGmail, SplitInBatches, ScheduleTrigger, LmChatOpenAi, TextClassifierなどのノードを使用。 OpenAI GPT-4によるGmailメールの自動分類とマーキング

前提条件
  • Googleアカウント + Gmail API認証情報
  • OpenAI API Key
ワークフロープレビュー
ノード接続関係を可視化、ズームとパンをサポート
ワークフローをエクスポート
以下のJSON設定をn8nにインポートして、このワークフローを使用できます
{
  "meta": {
    "instanceId": "d1786ab0d745a7498abf13a9c2cdabb1374c006e889b79eef64ce0386b8f8a41",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "434e0315-d478-4fc6-9d68-b6d83692d56d",
      "name": "スケジュールトリガー",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -220,
        -60
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "9a3551be-1e97-4b1a-986e-55adb27ea660",
      "name": "アイテムのループ処理",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        220,
        -40
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "e44d7114-2e55-4bc3-82d6-b9fdf10651d8",
      "name": "OpenAIチャットモデル",
      "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": "ラベル追加(高優先度)",
      "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": "ラベル追加(個人用)",
      "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": "ラベル追加(プロモーション)",
      "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": "付箋",
      "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": "付箋1",
      "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": "付箋2",
      "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": "付箋4",
      "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": "付箋5",
      "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": "ラベル分類器",
      "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": "付箋6",
      "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 - メール取得",
      "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
          }
        ]
      ]
    }
  }
}
よくある質問

このワークフローの使い方は?

上記のJSON設定コードをコピーし、n8nインスタンスで新しいワークフローを作成して「JSONからインポート」を選択、設定を貼り付けて認証情報を必要に応じて変更してください。

このワークフローはどんな場面に適していますか?

中級 - AI要約, マルチモーダルAI

有料ですか?

このワークフローは完全無料です。ただし、ワークフローで使用するサードパーティサービス(OpenAI APIなど)は別途料金が発生する場合があります。

ワークフロー情報
難易度
中級
ノード数15
カテゴリー2
ノードタイプ6
難易度説明

経験者向け、6-15ノードの中程度の複雑さのワークフロー

作成者
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

外部リンク
n8n.ioで表示

このワークフローを共有

カテゴリー

カテゴリー: 34