Gmail と GPT-4 を使用してメールの自動分類と返信生成を実現

中級

これはTicket Management, Multimodal AI分野の自動化ワークフローで、15個のノードを含みます。主にIf, Gmail, OpenAi, Webhook, GoogleSheetsなどのノードを使用。 Gmail と GPT-4 を使ってメールの分類と返信生成を自動化

前提条件
  • Googleアカウント + Gmail API認証情報
  • OpenAI API Key
  • HTTP Webhookエンドポイント(n8nが自動生成)
  • Google Sheets API認証情報
ワークフロープレビュー
ノード接続関係を可視化、ズームとパンをサポート
ワークフローをエクスポート
以下のJSON設定をn8nにインポートして、このワークフローを使用できます
{
  "meta": {
    "instanceId": "e7ccf4281d5afb175c79c02db95b45f15d5b53862cb6bc357c5e5bc26567f35c"
  },
  "nodes": [
    {
      "id": "759d4f88-c6de-4cee-af9a-628102d93200",
      "name": "📧 Gmail Webhookトリガー",
      "type": "n8n-nodes-base.webhook",
      "notes": "🔧 SETUP REQUIRED:\n1. Copy webhook URL after saving\n2. Configure Gmail webhook in Google Cloud Console\n3. Set up Gmail push notifications\n4. Test with sample email",
      "position": [
        -800,
        464
      ],
      "webhookId": "gmail-email-webhook",
      "parameters": {
        "path": "gmail-webhook",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 1
    },
    {
      "id": "000229fb-153f-4db4-ad19-cda7b78f3b57",
      "name": "📩 メール詳細取得",
      "type": "n8n-nodes-base.gmail",
      "notes": "🔧 SETUP REQUIRED:\n1. Create Gmail OAuth2 credentials\n2. Add scopes: gmail.readonly, gmail.modify\n3. Authorize the connection\n4. Test connection",
      "position": [
        -576,
        464
      ],
      "webhookId": "0d0edb78-408d-41be-b856-b3bdff6b4e4f",
      "parameters": {
        "messageId": "={{ $json.message.data.messageId }}",
        "operation": "get"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "zDJ58xrpmivGPuAW",
          "name": "Gmail account"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "daf62cc0-3dc9-4b67-801b-3c48eeb3d4df",
      "name": "🤖 AIメール分析",
      "type": "n8n-nodes-base.openAi",
      "notes": "🔧 SETUP REQUIRED:\n1. Get OpenAI API key\n2. Add to credentials\n3. Choose model (gpt-4 recommended)\n4. Adjust temperature for consistency\n5. Test with sample emails",
      "position": [
        -368,
        464
      ],
      "parameters": {
        "model": "gpt-4",
        "prompt": "=Analyze this email and provide a JSON response with the following structure:\n{\n  \"category\": \"urgent|important|promotional|spam|personal|work\",\n  \"sentiment\": \"positive|negative|neutral\",\n  \"priority\": \"high|medium|low\",\n  \"action_needed\": \"reply|forward|archive|delete|flag\",\n  \"summary\": \"brief summary in 1-2 sentences\",\n  \"suggested_response\": \"suggested response if reply needed\",\n  \"keywords\": [\"array\", \"of\", \"relevant\", \"keywords\"]\n}\n\nEmail details:\nFrom: {{ $node['📩 Get Email Details'].json.payload.headers.find(h => h.name === 'From').value }}\nSubject: {{ $node['📩 Get Email Details'].json.payload.headers.find(h => h.name === 'Subject').value }}\nBody: {{ $node['📩 Get Email Details'].json.snippet }}",
        "options": {
          "maxTokens": 1000,
          "temperature": 0.3
        },
        "requestOptions": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "OQJASLp1qn1StvpI",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "cf1eba5b-6645-4b21-b5bb-d8cb4ae5015e",
      "name": "🚦 優先度ルーター",
      "type": "n8n-nodes-base.if",
      "notes": "📝 POST-IT NOTE:\nRoutes emails based on AI analysis\n- High priority → Immediate notification\n- Medium/Low → Standard processing\n- Customize conditions as needed",
      "position": [
        -144,
        464
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ JSON.parse($json.choices[0].message.content).priority }}",
              "rightValue": "high"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "cbb52bdb-1065-4d4f-b09f-08e9367940f4",
      "name": "🚨 高優先度アラート",
      "type": "n8n-nodes-base.gmail",
      "notes": "🔧 SETUP REQUIRED:\n1. Update notification email address\n2. Customize alert message\n3. Consider using Slack/Teams instead\n4. Test notification delivery",
      "position": [
        80,
        352
      ],
      "webhookId": "76854229-c43b-4331-9860-d44d5e02b8ec",
      "parameters": {
        "message": "=High priority email received:\n\nFrom: {{ $node['📩 Get Email Details'].json.payload.headers.find(h => h.name === 'From').value }}\nSubject: {{ $node['📩 Get Email Details'].json.payload.headers.find(h => h.name === 'Subject').value }}\n\nAI Summary: {{ JSON.parse($node['🤖 AI Email Analyzer'].json.choices[0].message.content).summary }}\n\nSuggested Action: {{ JSON.parse($node['🤖 AI Email Analyzer'].json.choices[0].message.content).action_needed }}\n\nView in Gmail: https://mail.google.com/mail/u/0/#inbox/{{ $node['📩 Get Email Details'].json.id }}",
        "options": {},
        "subject": "🚨 High Priority Email Alert"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "zDJ58xrpmivGPuAW",
          "name": "Gmail account"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "b77a498a-001c-4029-a60a-1307dafa27fc",
      "name": "🛡️ スパム検出",
      "type": "n8n-nodes-base.if",
      "notes": "📝 POST-IT NOTE:\nDetects spam emails\n- Auto-delete or move to spam\n- Log spam attempts\n- Update spam filters",
      "position": [
        80,
        560
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ JSON.parse($node['🤖 AI Email Analyzer'].json.choices[0].message.content).category }}",
              "rightValue": "spam"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "1b7b3f23-01cb-42c0-8985-79696d0a38b2",
      "name": "🗑️ スパムへ移動",
      "type": "n8n-nodes-base.gmail",
      "notes": "📝 POST-IT NOTE:\nMoves spam to spam folder\n- Removes from inbox\n- Adds spam label\n- Consider auto-delete after time",
      "position": [
        304,
        656
      ],
      "webhookId": "ca7a4755-b0f4-4f7e-9b3a-4c20971b2ce1",
      "parameters": {
        "operation": "modify"
      },
      "typeVersion": 2
    },
    {
      "id": "63ae92b9-71c5-41e9-82f7-606985a1e4f3",
      "name": "💬 自動返信検出",
      "type": "n8n-nodes-base.if",
      "notes": "📝 POST-IT NOTE:\nDetects emails needing replies\n- AI suggests response\n- Option for auto-send or draft\n- Customize reply rules",
      "position": [
        304,
        480
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ JSON.parse($node['🤖 AI Email Analyzer'].json.choices[0].message.content).action_needed }}",
              "rightValue": "reply"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "778961c6-43d4-4624-abdb-3d6bebcf6249",
      "name": "📝 返信下書き作成",
      "type": "n8n-nodes-base.gmail",
      "notes": "📝 POST-IT NOTE:\nCreates AI-generated reply draft\n- Review before sending\n- Customize response style\n- Option to auto-send for simple cases",
      "position": [
        528,
        352
      ],
      "webhookId": "2af91249-fdb6-4447-b573-8c06249a52fe",
      "parameters": {
        "message": "={{ JSON.parse($node['🤖 AI Email Analyzer'].json.choices[0].message.content).suggested_response }}\n\n---\nThis is an AI-generated draft. Please review before sending.",
        "options": {},
        "subject": "=Re: {{ $node['📩 Get Email Details'].json.payload.headers.find(h => h.name === 'Subject').value }}",
        "resource": "draft"
      },
      "typeVersion": 2
    },
    {
      "id": "4a6f205f-80e6-42fc-be48-a672b76163ee",
      "name": "🏷️ メール分類",
      "type": "n8n-nodes-base.gmail",
      "notes": "🔧 SETUP REQUIRED:\n1. Create Gmail labels:\n   - URGENT, IMPORTANT\n   - PROMOTIONAL, PERSONAL\n   - WORK, PROJECTS\n2. Customize categories\n3. Set up label colors",
      "position": [
        528,
        560
      ],
      "webhookId": "8c0f452c-f1ac-4c72-8f92-834477ecd627",
      "parameters": {
        "operation": "modify"
      },
      "typeVersion": 2
    },
    {
      "id": "9be9a801-9b54-45f2-a820-4a35dc7915bb",
      "name": "📊 スプレッドシート記録",
      "type": "n8n-nodes-base.googleSheets",
      "notes": "🔧 SETUP REQUIRED:\n1. Create Google Sheets log\n2. Add headers: timestamp, messageId, from, subject, category, priority, sentiment, action_taken, ai_summary\n3. Share sheet with service account\n4. Update spreadsheet ID",
      "position": [
        752,
        464
      ],
      "parameters": {
        "resource": "spreadsheet",
        "operation": "appendOrUpdate"
      },
      "typeVersion": 4
    },
    {
      "id": "0f78144e-bb3a-4065-b15e-3294750b13b7",
      "name": "✅ Webhookレスポンス",
      "type": "n8n-nodes-base.respondToWebhook",
      "notes": "📝 POST-IT NOTE:\nSends response back to Gmail\n- Confirms processing\n- Includes analysis results\n- Required for webhook completion",
      "position": [
        960,
        464
      ],
      "parameters": {
        "options": {},
        "respondWith": "json",
        "responseBody": {
          "details": {
            "category": "={{ JSON.parse($node['🤖 AI Email Analyzer'].json.choices[0].message.content).category }}",
            "priority": "={{ JSON.parse($node['🤖 AI Email Analyzer'].json.choices[0].message.content).priority }}",
            "messageId": "={{ $node['📩 Get Email Details'].json.id }}",
            "action_taken": "={{ JSON.parse($node['🤖 AI Email Analyzer'].json.choices[0].message.content).action_needed }}"
          },
          "message": "Email processed successfully",
          "success": true
        }
      },
      "typeVersion": 1
    },
    {
      "id": "fe23603a-8174-48ee-8ebf-3cabf507ecd7",
      "name": "付箋9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -768,
        -320
      ],
      "parameters": {
        "color": 3,
        "width": 576,
        "height": 560,
        "content": "## Need a tailor-made workflow? Tell me about your business and get a free proposal:\n\n**[Start here → Custom Automation Form](https://taskmorphr.com/contact)**\n\n---\n## 📈 Cost-Savings Snapshot  \nCurious what automation could save you?  \nRun the 60-second calculator:\n\n**[ROI / Cost Comparison](https://taskmorphr.com/cost-comparison)**\n\n---\n### ✉️ Reach me directly  \n`paul@taskmorphr.com`"
      },
      "typeVersion": 1
    },
    {
      "id": "4ca8fea5-6f43-41f9-9e68-e2dca7f73d8e",
      "name": "付箋10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -464,
        64
      ],
      "parameters": {
        "color": 3,
        "width": 224,
        "height": 128,
        "content": "### 🛠️ Build it yourself  \nBrowse every ready-made workflow:  \n[Full Template Pack — coming soon](https://n8n.io/creators/diagopl/)\n"
      },
      "typeVersion": 1
    },
    {
      "id": "f2cbe293-04fa-48c4-8849-4637063becf3",
      "name": "付箋",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1776,
        -304
      ],
      "parameters": {
        "width": 848,
        "height": 2272,
        "content": "# Gmail AI Email Manager - Setup Guide\n\n## 🎯 Workflow Overview\n\nThis workflow will create an intelligent Gmail email manager that can:\n- Monitor incoming emails via webhook\n- Analyze email content using AI\n- Categorize emails automatically\n- Generate smart responses\n- Take actions based on email content\n- Send notifications for important emails\n\n## 📋 Pre-Setup Checklist\n\nBefore we build the workflow, let me gather the necessary information and validate our approach.\n\n### Phase 1: Discovery & Planning\n- [ ] Search for Gmail nodes\n- [ ] Find AI analysis nodes\n- [ ] Identify webhook trigger options\n- [ ] Check notification nodes\n\n### Phase 2: Configuration Requirements\n- [ ] Gmail API credentials\n- [ ] AI service (OpenAI/Claude) API key\n- [ ] Webhook URL setup\n- [ ] Email classification rules\n\n## 🔧 Setup Instructions\n\n### Step 1: Gmail API Setup\n1. Go to Google Cloud Console\n2. Create new project or select existing\n3. Enable Gmail API\n4. Create OAuth 2.0 credentials\n5. Add authorized redirect URI: `https://your-n8n-instance.com/rest/oauth2-credential/callback`\n\n### Step 2: AI Service Setup\nChoose one of the following:\n- **OpenAI**: Get API key from platform.openai.com\n- **Claude**: Get API key from console.anthropic.com\n- **Local AI**: Set up Ollama or similar\n\n### Step 3: n8n Credentials\n1. Gmail OAuth2: Add client ID, secret, and scopes\n2. AI Service: Add API key\n3. Webhook: Configure webhook URL\n\n# Gmail AI Email Manager - Setup Guide\n\n## 🔧 Quick Setup Checklist\n\n### 1. Google Cloud Console\n- [ ] Enable Gmail API\n- [ ] Create OAuth2 credentials  \n- [ ] Add redirect URI: `https://your-n8n.com/rest/oauth2-credential/callback`\n- [ ] Set up Gmail push notifications with Pub/Sub\n\n### 2. API Keys\n- [ ] Get OpenAI API key from platform.openai.com\n- [ ] Create Google Sheets for logging (optional)\n\n### 3. n8n Credentials\n- [ ] **Gmail OAuth2**: Client ID, Secret, Scopes: `gmail.readonly,gmail.modify,gmail.compose`\n- [ ] **OpenAI API**: Your API key\n\n### 4. Gmail Labels (Create these)\n- [ ] URGENT (red) \n- [ ] IMPORTANT (orange)\n- [ ] PROMOTIONAL (purple)\n- [ ] PERSONAL (green) \n- [ ] WORK (blue)\n- [ ] SPAM (gray)\n\n### 5. Update Workflow Values\n- [ ] High Priority Alert: Change notification email\n- [ ] Spreadsheet Log: Update sheet ID (if using)\n- [ ] Webhook: Copy URL after saving workflow\n\n### 6. Test\n- [ ] Save & activate workflow\n- [ ] Send test email to Gmail\n- [ ] Check execution log\n- [ ] Verify auto-categorization works\n\n**That's it! Your AI email manager is ready! 🚀**"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "1b7b3f23-01cb-42c0-8985-79696d0a38b2": {
      "main": [
        [
          {
            "node": "9be9a801-9b54-45f2-a820-4a35dc7915bb",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "cf1eba5b-6645-4b21-b5bb-d8cb4ae5015e": {
      "main": [
        [
          {
            "node": "cbb52bdb-1065-4d4f-b09f-08e9367940f4",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "b77a498a-001c-4029-a60a-1307dafa27fc",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "b77a498a-001c-4029-a60a-1307dafa27fc": {
      "main": [
        [
          {
            "node": "1b7b3f23-01cb-42c0-8985-79696d0a38b2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "63ae92b9-71c5-41e9-82f7-606985a1e4f3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "000229fb-153f-4db4-ad19-cda7b78f3b57": {
      "main": [
        [
          {
            "node": "daf62cc0-3dc9-4b67-801b-3c48eeb3d4df",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "daf62cc0-3dc9-4b67-801b-3c48eeb3d4df": {
      "main": [
        [
          {
            "node": "cf1eba5b-6645-4b21-b5bb-d8cb4ae5015e",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "9be9a801-9b54-45f2-a820-4a35dc7915bb": {
      "main": [
        [
          {
            "node": "0f78144e-bb3a-4065-b15e-3294750b13b7",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "778961c6-43d4-4624-abdb-3d6bebcf6249": {
      "main": [
        [
          {
            "node": "4a6f205f-80e6-42fc-be48-a672b76163ee",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "4a6f205f-80e6-42fc-be48-a672b76163ee": {
      "main": [
        [
          {
            "node": "9be9a801-9b54-45f2-a820-4a35dc7915bb",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "63ae92b9-71c5-41e9-82f7-606985a1e4f3": {
      "main": [
        [
          {
            "node": "778961c6-43d4-4624-abdb-3d6bebcf6249",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "4a6f205f-80e6-42fc-be48-a672b76163ee",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "cbb52bdb-1065-4d4f-b09f-08e9367940f4": {
      "main": [
        [
          {
            "node": "4a6f205f-80e6-42fc-be48-a672b76163ee",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "759d4f88-c6de-4cee-af9a-628102d93200": {
      "main": [
        [
          {
            "node": "000229fb-153f-4db4-ad19-cda7b78f3b57",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
よくある質問

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

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

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

中級 - チケット管理, マルチモーダルAI

有料ですか?

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

関連ワークフロー

Outlook、OpenAI、JIRA を基にした AI サポート オートメーション
Outlook、OpenAI、JIRA チケットを統合した AI サポート型高度自動化システム
If
Jira
Gmail
+
If
Jira
Gmail
18 ノードAnnie To
チケット管理
競合他社コンテンツギャップ分析ツール:構題マッピングの自動化
Gemini AI、Apify、Google Sheetsを使用して競合企業のコンテンツギャップを分析
If
Set
Code
+
If
Set
Code
30 ノードMychel Garzon
その他
複数の採用サイトからの求人情報の自動化
5 つの求人プラットフォームと AI リジュームジェネレーターを使った就職・応募の自動化
If
Set
Code
+
If
Set
Code
34 ノードGerald Denor
個人の生産性
チケットバックエンド
アクティビティチケットバックエンド:Google SheetsとGmailを使ってQRコード入りチケットを自動生成
If
Code
Gmail
+
If
Code
Gmail
35 ノードKhairul Muhtadin
コンテンツ作成
AI を活用した WhatsApp カスタマーサービス(GPT-4、スマートルーティング、ナレッジベース)
AI ベースの WhatsApp カスタマー サービス (GPT-4、インテリジェント ルーティング、ナレッジ ベース)
Set
Gmail
Merge
+
Set
Gmail
Merge
45 ノードPaul
AIチャットボット
GmailとGPTに基づくAI駆動メール分類および自動返信システム
GPT-4.1-miniを使用して分類し、Gmailで自動返信を行うことでメールセグメントを自動化
If
Set
Gmail
+
If
Set
Gmail
24 ノードGiovanni Beggiato
チケット管理
ワークフロー情報
難易度
中級
ノード数15
カテゴリー2
ノードタイプ7
難易度説明

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

作成者

Automation expert & n8n power user. I build advanced workflows combining AI, outbound, and business logic. Grab my templates or reach out for custom builds.

外部リンク
n8n.ioで表示

このワークフローを共有

カテゴリー

カテゴリー: 34