AI分析付きメールアジェント
上級
これは自動化ワークフローで、18個のノードを含みます。主にCode, Gmail, Notion, GmailTool, GmailTriggerなどのノードを使用。 Gemini AIを使った自動メール管理:Gmail要約、タグ付け、Notion/テーブルへの記録
前提条件
- •Googleアカウント + Gmail API認証情報
- •Notion API Key
- •Google Sheets API認証情報
- •Google Gemini API Key
使用ノード (18)
カテゴリー
-
ワークフロープレビュー
ノード接続関係を可視化、ズームとパンをサポート
ワークフローをエクスポート
以下のJSON設定をn8nにインポートして、このワークフローを使用できます
{
"id": "5vu0NifxPdAhR0hK",
"meta": {
"instanceId": "fee12d331bbd0b438da1621758e24b51ca0d8413c66e935fc3651aee72389944",
"templateCredsSetupCompleted": true
},
"name": "Email Agent with AI Analysis",
"tags": [],
"nodes": [
{
"id": "484fdb46-d4aa-474c-ada7-23325c27494a",
"name": "メールデータ処理",
"type": "n8n-nodes-base.code",
"position": [
-672,
-48
],
"parameters": {
"jsCode": "// Process email data from Gmail trigger\nconst items = [];\n\nfor (const item of $input.all()) {\n const emailData = item.json;\n \n // --- Handle sender information ---\n let senderEmail = '';\n let senderName = '';\n\n if (emailData.from?.value?.[0]) {\n senderEmail = emailData.from.value[0].address || '';\n senderName = emailData.from.value[0].name || senderEmail;\n } else if (emailData.from?.text) {\n const emailMatch = emailData.from.text.match(/<([^>]+)>/) || \n emailData.from.text.match(/([^\\s]+@[^\\s]+)/);\n senderEmail = emailMatch ? emailMatch[1] : emailData.from.text;\n \n const nameMatch = emailData.from.text.match(/^([^<]+)/);\n senderName = nameMatch ? nameMatch[1].trim().replace(/\\\"/g, '') : senderEmail;\n }\n\n // --- Format date ---\n const receivedDate = new Date(emailData.date || emailData.receivedTime);\n const formattedDate = receivedDate.toLocaleString('en-US', {\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n hour12: true\n });\n\n // --- Extract content ---\n let emailContent = '';\n \n // 1. Plain text version\n if (emailData.text) {\n emailContent = emailData.text;\n } \n // 2. HTML version\n else if (emailData.html) {\n emailContent = emailData.html\n .replace(/<style[^>]*>.*?<\\/style>/gs, '') // Remove CSS\n .replace(/<[^>]*>/g, ' ') // Strip HTML tags\n .replace(/\\s+/g, ' ') // Collapse whitespace\n .trim();\n }\n // 3. Fallback\n else if (emailData.body || emailData.textPlain || emailData.textHtml) {\n emailContent = emailData.body || emailData.textPlain || emailData.textHtml;\n }\n\n // --- Truncate if too long ---\n const maxContentLength = 5000;\n if (emailContent.length > maxContentLength) {\n emailContent = emailContent.substring(0, maxContentLength) + '... [truncated]';\n }\n\n // --- Create final data object ---\n const rowData = {\n messageId: emailData.id || emailData.messageId || '',\n threadId: emailData.threadId || '',\n Date: formattedDate,\n 'Sender Name': senderName,\n 'Sender Email': senderEmail,\n Subject: emailData.subject || 'No Subject',\n Content: emailContent,\n 'Has Attachments': emailData.attachments?.length > 0 ? 'Yes' : 'No'\n };\n \n items.push({ json: rowData });\n}\n\nreturn items;\n"
},
"typeVersion": 2
},
{
"id": "bc108b82-4b56-4f1b-a49d-47bfc08c1e58",
"name": "AIメールアナライザー",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
-288,
-48
],
"parameters": {
"text": "=You are an intelligent email assistant. Analyze the following email and perform these tasks:\n\n1. Create a comprehensive summary of the email without removing any essential information\n2. Determine the most appropriate label category for this email from the following options:\n - Work\n - Personal\n - Finance\n - Marketing/Promotional\n - Newsletter\n - Important\n - Follow-up Required\n - Project Updates\n - Meeting/Calendar\n - Support/Customer Service\n - Social\n - Travel\n - Bills/Invoices\n - Spam\n\nIf none of these labels fit perfectly, suggest a new label that would be most appropriate.\n\nEmail Details:\nFrom: {{ $json['Sender Name'] }} ({{ $json['Sender Email'] }})\nSubject: {{ $json.Subject }}\nContent: {{ $json.Content }}\nHas Attachments: {{ $json['Has Attachments'] }}\n\nProvide your response in the following JSON format:\n{\n \"summary\": \"detailed summary here\",\n \"suggestedLabel\": \"label name\",\n \"createNewLabel\": true/false,\n \"priority\": \"high/medium/low\",\n \"actionRequired\": true/false,\n \"keyPoints\": [\"point1\", \"point2\"]\n}",
"options": {}
},
"typeVersion": 1
},
{
"id": "1c47f4e7-6d29-4842-8e59-c96bedeb12c9",
"name": "Gmailラベル作成",
"type": "n8n-nodes-base.gmail",
"onError": "continueRegularOutput",
"position": [
304,
-48
],
"webhookId": "ff00793b-2048-49c5-ae7a-dc64bfa0d2a9",
"parameters": {
"name": "={{ $json.output.output.emailParserOutput.emailLabel }}",
"options": {},
"resource": "label",
"operation": "create"
},
"credentials": {
"gmailOAuth2": {
"id": "8aorLnmRyAjVbcKV",
"name": "Gmail account"
}
},
"typeVersion": 2,
"continueOnFail": true
},
{
"id": "70af1293-925b-4396-a36c-8236cbd7ddda",
"name": "メールにラベル追加",
"type": "n8n-nodes-base.gmail",
"position": [
1424,
-48
],
"webhookId": "825a8453-c06a-4f08-93ed-072e86f5ddb9",
"parameters": {
"labelIds": "={{ $json.output }}",
"messageId": "={{ $('Process Email Data').item.json.messageId }}",
"operation": "addLabels"
},
"credentials": {
"gmailOAuth2": {
"id": "8aorLnmRyAjVbcKV",
"name": "Gmail account"
}
},
"typeVersion": 2
},
{
"id": "1a9df30f-e473-4ebf-ade4-fda37891f79f",
"name": "構造化出力パーサー",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
-208,
224
],
"parameters": {
"jsonSchemaExample": "{\n \"emailParserOutput\": {\n \"messageId\": \"string - unique Gmail message ID\",\n \"threadId\": \"string - Gmail thread ID this email belongs to\",\n \"summary\": \"string - concise 1-2 sentence summary of the email content\",\n \"emailLabel\": \"string - label or category to assign (e.g., 'Finance', 'Meetings', 'Support', 'Marketing', 'Personal', 'Recruitment', 'General')\"\n }\n}\n"
},
"typeVersion": 1.3
},
{
"id": "ce8d7ab7-32e5-4d96-839c-84ded9261110",
"name": "ラベル取得",
"type": "n8n-nodes-base.gmailTool",
"position": [
976,
112
],
"webhookId": "3d8f3a77-55e9-40f6-999a-86417c938f8f",
"parameters": {
"resource": "label",
"returnAll": true
},
"credentials": {
"gmailOAuth2": {
"id": "8aorLnmRyAjVbcKV",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "9ba1e386-a291-4672-9b55-4c6abe3ada00",
"name": "Notionに記録",
"type": "n8n-nodes-base.notion",
"position": [
896,
496
],
"parameters": {
"options": {},
"resource": "databasePage",
"databaseId": {
"__rl": true,
"mode": "list",
"value": "4b672fe9-afc9-4da3-8a1b-1a35b1b61513",
"cachedResultUrl": "https://www.notion.so/4b672fe9afc94da38a1b1a35b1b61513",
"cachedResultName": "Email Summary Database"
},
"propertiesUi": {
"propertyValues": [
{
"key": "Message ID|rich_text",
"textContent": "={{ $('Process Email Data').item.json.messageId }}"
},
{
"key": "Sender Name|rich_text",
"textContent": "={{ $('Process Email Data').item.json['Sender Name'] }}"
},
{
"key": "Sender Email|email",
"emailValue": "={{ $('Process Email Data').item.json['Sender Email'] }}"
},
{
"key": "Subject|title",
"title": "={{ $('Process Email Data').item.json.Subject }}"
},
{
"key": "Summary|rich_text",
"textContent": "={{ $('AI Email Analyzer').item.json.output.output.emailParserOutput.summary }}"
},
{
"key": "Date & Time|date",
"date": "={{ $('Process Email Data').item.json.Date }}"
},
{
"key": "Label|multi_select",
"multiSelectValue": "={{ $('AI Email Analyzer').item.json.output.output.emailParserOutput.emailLabel }}"
}
]
}
},
"credentials": {
"notionApi": {
"id": "rs2HR8ueV6i3Q289",
"name": "Email Summary"
}
},
"typeVersion": 2.2
},
{
"id": "2f65eb86-855b-468f-88dd-d91448fa50da",
"name": "Googleスプレッドシートに記録",
"type": "n8n-nodes-base.googleSheets",
"position": [
720,
496
],
"parameters": {
"columns": {
"value": {
"Date": "={{ $('Process Email Data').item.json.Date }}",
"Label": "={{ $('AI Email Analyzer').item.json.output.output.emailParserOutput.emailLabel }}",
"Subject": "={{ $('Process Email Data').item.json.Subject }}",
"Summary": "={{ $('Process Email Data').item.json.Content }}",
"Message ID": "={{ $('Process Email Data').item.json.messageId }}",
"Sender Name": "={{ $('Process Email Data').item.json['Sender Name'] }}",
"Sender Email": "={{ $('Process Email Data').item.json['Sender Email'] }}"
},
"schema": [
{
"id": "Message ID",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Message ID",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Sender Name",
"type": "string",
"display": true,
"required": false,
"displayName": "Sender Name",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Sender Email",
"type": "string",
"display": true,
"required": false,
"displayName": "Sender Email",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Subject",
"type": "string",
"display": true,
"required": false,
"displayName": "Subject",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Summary",
"type": "string",
"display": true,
"required": false,
"displayName": "Summary",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Date",
"type": "string",
"display": true,
"required": false,
"displayName": "Date",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Label",
"type": "string",
"display": true,
"required": false,
"displayName": "Label",
"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/1Vf3_L3dDbwSwY9AAvnwBM08sBVxrYpgkFLPzamrqwRo/edit#gid=0",
"cachedResultName": "Sheet1"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1Vf3_L3dDbwSwY9AAvnwBM08sBVxrYpgkFLPzamrqwRo",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Vf3_L3dDbwSwY9AAvnwBM08sBVxrYpgkFLPzamrqwRo/edit?usp=drivesdk",
"cachedResultName": "Email Summary Sheet"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "P5uDkwj3uNdQGVvH",
"name": "Google Sheets account 2"
}
},
"typeVersion": 4
},
{
"id": "3036c3ee-4d54-489b-b066-32d6ff0079d8",
"name": "新着メール時",
"type": "n8n-nodes-base.gmailTrigger",
"position": [
-912,
-48
],
"parameters": {
"simple": false,
"filters": {
"labelIds": [
"INBOX"
]
},
"options": {
"downloadAttachments": false
},
"pollTimes": {
"item": [
{
"mode": "=everyHour",
"minute": 59
}
]
}
},
"credentials": {
"gmailOAuth2": {
"id": "8aorLnmRyAjVbcKV",
"name": "Gmail account"
}
},
"typeVersion": 1
},
{
"id": "01278d0b-76e7-42f1-b184-5ccfbd687856",
"name": "付箋ノート",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1008,
-320
],
"parameters": {
"width": 560,
"height": 432,
"content": "# Gmail Trigger and Email Process\n\n## - Gmail Trigger Node \n- Triggers on every message (default).\n- You can change on how often it triggers (default 59 mins)\n\n## - Process Email Data\n- Takes out essential data from the email received"
},
"typeVersion": 1
},
{
"id": "de26393b-c208-472f-920d-af5c60fc3932",
"name": "付箋ノート1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-128,
432
],
"parameters": {
"color": 2,
"width": 464,
"height": 192,
"content": "# AI Node\n## You can choose your\n## own favourite LLM"
},
"typeVersion": 1
},
{
"id": "ce139c50-bc92-4636-9784-47a4cc57e4ee",
"name": "Google Geminiチャットモデル",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"position": [
144,
480
],
"parameters": {
"options": {}
},
"credentials": {
"googlePalmApi": {
"id": "4orThiegw1mzxjwh",
"name": "Google Gemini(PaLM) Api account"
}
},
"typeVersion": 1
},
{
"id": "75410ce2-1276-4bfe-80c9-d093989a125d",
"name": "付箋ノート2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-384,
-224
],
"parameters": {
"color": 5,
"width": 448,
"height": 336,
"content": "# Email Ananlyzer\n\n### Analyzes the email received, summarizes the whole email and suggests the most specific label for the mail"
},
"typeVersion": 1
},
{
"id": "9e64d00e-88da-4be1-9d06-614e12c70081",
"name": "付箋ノート3",
"type": "n8n-nodes-base.stickyNote",
"position": [
112,
-320
],
"parameters": {
"color": 2,
"width": 432,
"height": 432,
"content": "# Creates Label\n\n### Creates the label received by **AI Email Analyzer Node**\n\n### If label is already there, the workflow continues"
},
"typeVersion": 1
},
{
"id": "21a103b8-b239-4000-bc12-a57df7b1a5ae",
"name": "ラベルエージェント",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
784,
-48
],
"parameters": {
"text": "=Your work is basicaly to give the \"Add Label - Gmail Node\" the correct label ID\n\nYour Work -:\n\n1. The Label which needs to attached will be given by {{ $('AI Email Analyzer').item.json.output.output.emailParserOutput.emailLabel }}\n2. After you get the label, you need to take out the correct label id from {{ $json.id }}\n3. You need to use the Get Label tool to get all the labels and use that tool to take the correct label and label id.\n4. After you get the label id, you just need to output that label id and NOTHING ELSE\n\n**OUTPUT** Only Label ID from {{ $json.id }}",
"options": {},
"promptType": "define"
},
"typeVersion": 2.2
},
{
"id": "f52d7b64-1614-4653-ae46-5aef4a43aedf",
"name": "付箋ノート4",
"type": "n8n-nodes-base.stickyNote",
"position": [
672,
-320
],
"parameters": {
"color": 6,
"width": 464,
"height": 576,
"content": "# AI Label Assigner\n\n### Gets the label and forward the appropriate Label Code for the Email received"
},
"typeVersion": 1
},
{
"id": "b3a4c0a0-26e8-419e-a1f9-4efcd650a54c",
"name": "付箋ノート5",
"type": "n8n-nodes-base.stickyNote",
"position": [
1232,
-192
],
"parameters": {
"color": 5,
"width": 416,
"height": 448,
"content": "# Add the Label\n\n**NOTE:** Only add the **Label ID** or else the workflow will fail"
},
"typeVersion": 1
},
{
"id": "1fc628e0-7447-4440-8d30-65633736705f",
"name": "付箋ノート6",
"type": "n8n-nodes-base.stickyNote",
"position": [
592,
352
],
"parameters": {
"color": 4,
"width": 576,
"height": 304,
"content": "# Logging the details in G-Sheet and Notion"
},
"typeVersion": 1
}
],
"active": true,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "a0199094-3c1f-4c24-be3e-fb812070041c",
"connections": {
"ce8d7ab7-32e5-4d96-839c-84ded9261110": {
"ai_tool": [
[
{
"node": "21a103b8-b239-4000-bc12-a57df7b1a5ae",
"type": "ai_tool",
"index": 0
}
]
]
},
"21a103b8-b239-4000-bc12-a57df7b1a5ae": {
"main": [
[
{
"node": "70af1293-925b-4396-a36c-8236cbd7ddda",
"type": "main",
"index": 0
}
]
]
},
"3036c3ee-4d54-489b-b066-32d6ff0079d8": {
"main": [
[
{
"node": "484fdb46-d4aa-474c-ada7-23325c27494a",
"type": "main",
"index": 0
}
]
]
},
"bc108b82-4b56-4f1b-a49d-47bfc08c1e58": {
"main": [
[
{
"node": "1c47f4e7-6d29-4842-8e59-c96bedeb12c9",
"type": "main",
"index": 0
}
]
]
},
"70af1293-925b-4396-a36c-8236cbd7ddda": {
"main": [
[
{
"node": "2f65eb86-855b-468f-88dd-d91448fa50da",
"type": "main",
"index": 0
},
{
"node": "9ba1e386-a291-4672-9b55-4c6abe3ada00",
"type": "main",
"index": 0
}
]
]
},
"1c47f4e7-6d29-4842-8e59-c96bedeb12c9": {
"main": [
[
{
"node": "21a103b8-b239-4000-bc12-a57df7b1a5ae",
"type": "main",
"index": 0
}
]
]
},
"484fdb46-d4aa-474c-ada7-23325c27494a": {
"main": [
[
{
"node": "bc108b82-4b56-4f1b-a49d-47bfc08c1e58",
"type": "main",
"index": 0
}
]
]
},
"ce139c50-bc92-4636-9784-47a4cc57e4ee": {
"ai_languageModel": [
[
{
"node": "21a103b8-b239-4000-bc12-a57df7b1a5ae",
"type": "ai_languageModel",
"index": 0
},
{
"node": "bc108b82-4b56-4f1b-a49d-47bfc08c1e58",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"1a9df30f-e473-4ebf-ade4-fda37891f79f": {
"ai_outputParser": [
[
{
"node": "bc108b82-4b56-4f1b-a49d-47bfc08c1e58",
"type": "ai_outputParser",
"index": 0
}
]
]
}
}
}よくある質問
このワークフローの使い方は?
上記のJSON設定コードをコピーし、n8nインスタンスで新しいワークフローを作成して「JSONからインポート」を選択、設定を貼り付けて認証情報を必要に応じて変更してください。
このワークフローはどんな場面に適していますか?
上級
有料ですか?
このワークフローは完全無料です。ただし、ワークフローで使用するサードパーティサービス(OpenAI APIなど)は別途料金が発生する場合があります。
関連ワークフロー
n8nノードの探索(可視化リファレンスライブラリ内)
n8nノードを可視化リファレンスライブラリで探索
If
Ftp
Set
+
If
Ftp
Set
113 ノードI versus AI
その他
AIメール分诊与GPT-4警报系统及Telegram通知
AIメール分诊与GPT-4警报系统及Telegram通知
If
Set
Gmail
+
If
Set
Gmail
104 ノードPeter Joslyn
サポート
AI驱动のメール分诊与自動回复系统,統合OpenAIエージェントとGmail
AI驱动のメール分诊与自動回复系统,統合OpenAIエージェントとGmail
If
Set
Gmail
+
If
Set
Gmail
68 ノードAbdullahi Ahmed
コンテンツ作成
ブログ投稿自動化とSNSプロモーションエージェント
GPT-4、Perplexity、WordPressを使用したSEOブログ作成の自動化+ソーシャルメディア
Set
Code
Gmail
+
Set
Code
Gmail
79 ノードLukaszB
デザイン
自動化学術論文メタデータおよび変数抽出(GeminiからGoogle Sheetsへ)
論文のメタデータおよび変数抽出の自動化:GeminiからGoogle Sheetsへ
Set
Code
Wait
+
Set
Code
Wait
39 ノードOwenLee
文書抽出
Gmail、GPT-4、ベクター知識ベースを使用した顧客サポートシステムの自動化
自動顧客サポートシステム(Gmail、GPT-4、ベクター知識ベース)
If
Set
Code
+
If
Set
Code
32 ノードKhair Ahammed
AI RAG検索拡張