{
  "name": "AI Gmail Auto-Draft Replies",
  "nodes": [
    {
      "parameters": {
        "content": "## AI Draft Replies for Every Gmail Email\n\nOpen your inbox to find a sensible draft reply already written under every email - you just edit and send. Cuts email time roughly in half.\n\n**Setup time:** 15 minutes  ·  **Level:** Intermediate\n\n**You'll need accounts/credentials for:** Gmail, OpenAI\n\n**Setup steps:**\n1. Connect your Gmail account in both Gmail nodes.\n2. Edit the system prompt in the AI node: your name, sign-off, tone, and any standing rules (pricing answers, links you always share).\n3. Optionally narrow the trigger filter, e.g. exclude newsletters with '-category:promotions'.\n4. Activate, then email yourself from another address and check your drafts folder.\n\nFree templates and updates: navkhan103.github.io",
        "height": 530,
        "width": 400,
        "color": 4
      },
      "id": "sticky-setup",
      "name": "Setup — read me first",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -440,
        -40
      ]
    },
    {
      "parameters": {
        "content": "### How it runs\n\nStarts from **New Email**.\n\n1. A Gmail Trigger polls for new emails in your inbox.\n2. An AI node reads the sender, subject, and body, and writes a reply following your style instructions.\n3. A Gmail node saves the reply as a draft on the same thread - it never sends anything.\n4. You open the thread, tweak the draft if needed, and hit send.",
        "height": 348,
        "width": 400,
        "color": 7
      },
      "id": "sticky-how",
      "name": "How it runs",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -440,
        530
      ]
    },
    {
      "parameters": {
        "content": "### If something breaks\n\nThe read and AI nodes here **retry 3× automatically** (5s apart), which absorbs rate limits and brief timeouts.\n\nNodes that **send or write deliberately do not retry** — a send that reached the far end but lost its response would otherwise fire twice, so you'd get duplicate messages or duplicate rows.\n\nTo be told when one of those fails, build a workflow starting with an **Error Trigger** node that posts to Slack or email, then set it under **three-dot menu > Settings > Error Workflow**. Do it once and point every workflow at it.",
        "height": 400,
        "width": 400,
        "color": 3
      },
      "id": "sticky-fail",
      "name": "If something breaks",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -440,
        918
      ]
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "simple": false,
        "filters": {
          "q": "in:inbox -category:promotions -category:social"
        },
        "options": {}
      },
      "id": "a7b8c9d0-0001-4000-8000-000000000001",
      "name": "New Email",
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5.6-luna"
        },
        "messages": {
          "values": [
            {
              "content": "You draft email replies for me. My name is YOUR NAME. Tone: friendly, direct, no fluff. Sign off with 'Best,\\nYOUR NAME'. If the email asks something you cannot know, draft a polite holding reply. Output only the reply body, no subject line.",
              "role": "system"
            },
            {
              "content": "=From: {{ $json.from.value[0].address }}\nSubject: {{ $json.subject }}\n\n{{ $json.text }}",
              "role": "user"
            }
          ]
        }
      },
      "id": "a7b8c9d0-0002-4000-8000-000000000002",
      "name": "Write Draft Reply",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        220,
        0
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000
    },
    {
      "parameters": {
        "resource": "draft",
        "subject": "=Re: {{ $('New Email').item.json.subject }}",
        "emailType": "text",
        "message": "={{ $json.message.content }}",
        "options": {
          "threadId": "={{ $('New Email').item.json.threadId }}",
          "sendTo": "={{ $('New Email').item.json.from.value[0].address }}"
        }
      },
      "id": "a7b8c9d0-0003-4000-8000-000000000003",
      "name": "Save as Gmail Draft",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        440,
        0
      ]
    }
  ],
  "connections": {
    "New Email": {
      "main": [
        [
          {
            "node": "Write Draft Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write Draft Reply": {
      "main": [
        [
          {
            "node": "Save as Gmail Draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}