{
  "name": "AI Email Autoresponder for Leads with n8n (free JSON)",
  "nodes": [
    {
      "id": "46330a1e-99c2-4e0b-b2ef-fbc1ac382402",
      "name": "Email Trigger (IMAP)",
      "type": "n8n-nodes-base.emailReadImap",
      "notes": "Watches one mailbox folder over IMAP and starts the workflow for each new message it picks up.",
      "position": [
        0,
        0
      ],
      "parameters": {
        "options": {},
        "postProcessAction": "nothing"
      },
      "notesInFlow": true,
      "typeVersion": 2
    },
    {
      "id": "2a2a35ef-23cf-4612-ac7d-21f91f21a2c6",
      "name": "Filter",
      "type": "n8n-nodes-base.filter",
      "notes": "Lets a message continue only if the AI said it is a lead.",
      "position": [
        608,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "4da59f1a-dd10-450e-a113-d193b63fcdac",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.message.content.lead.toBoolean() }}",
              "rightValue": ""
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 2.2
    },
    {
      "id": "ddba86b4-fe7d-4c36-b42c-6dde939d05f4",
      "name": "Get Message",
      "type": "n8n-nodes-base.gmail",
      "notes": "Searches Gmail for messages from the same sender with the same subject. Each match makes the next step run once.",
      "position": [
        1216,
        0
      ],
      "parameters": {
        "filters": {
          "q": "=from:\"{{ $('Email Trigger (IMAP)').item.json.from }}\" subject:\"{{ $('Email Trigger (IMAP)').item.json.subject }}\" "
        },
        "operation": "getAll"
      },
      "typeVersion": 2.1
    },
    {
      "id": "f1b3f3c5-a2fe-436e-a272-d3958ccab3e5",
      "name": "Reply to Message",
      "type": "n8n-nodes-base.gmail",
      "notes": "Sends the AI text as a reply to the message identified by the original IMAP message id.",
      "position": [
        1536,
        0
      ],
      "parameters": {
        "message": "={{ $('Reply with customized message').item.json.message.content }}",
        "options": {},
        "emailType": "text",
        "messageId": "={{ $('Email Trigger (IMAP)').item.json.metadata['message-id'] }}",
        "operation": "reply"
      },
      "notesInFlow": true,
      "typeVersion": 2.1
    },
    {
      "id": "2489c348-5d8e-4564-915f-1d933eae745b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1456,
        -320
      ],
      "parameters": {
        "color": 3,
        "height": 256,
        "content": "## Reply to Message\n\nSends the reply as plain text from the connected Gmail account. The message id it uses comes from the IMAP step. Test that Gmail accepts it."
      },
      "typeVersion": 1
    },
    {
      "id": "e7617aa6-1104-4cc9-af36-80d7c19cdc59",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -48,
        -320
      ],
      "parameters": {
        "color": 4,
        "width": 208,
        "height": 256,
        "content": "## Email Trigger (IMAP)\n\nConnect an IMAP credential and choose the folder to watch. Every message it picks up starts one run. Use a test mailbox first."
      },
      "typeVersion": 1
    },
    {
      "id": "33fe0c88-6540-4087-bb60-ac6c4de9f6d3",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        224,
        -320
      ],
      "parameters": {
        "color": 7,
        "height": 256,
        "content": "## Filter leads\n\nThe AI reads the plain-text body and answers with JSON such as {\"lead\": \"true\"}. Replace YOUR_SERVICE_OR_OFFER in the prompt with what you sell. The message text is passed to the AI as it is, so a sender can try to give it instructions."
      },
      "typeVersion": 1
    },
    {
      "id": "54c5cf98-a106-4e3b-ad2d-d57fb8095044",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        528,
        -320
      ],
      "parameters": {
        "color": 5,
        "height": 256,
        "content": "## Filter\n\nOnly messages the AI marked as leads pass. Everything else stops here and gets no reply and no log."
      },
      "typeVersion": 1
    },
    {
      "id": "94aedcf9-6abb-40e0-9856-e2fc3a84116a",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        832,
        -320
      ],
      "parameters": {
        "color": 7,
        "height": 256,
        "content": "## Reply with customized message\n\nThe AI writes the reply. Replace YOUR_BUSINESS_AND_SERVICE, YOUR_NAME, YOUR_COMPANY and YOUR_ONE_LINE_DESCRIPTION in the prompt and in the example. It only knows the email text, so read its output before you trust it."
      },
      "typeVersion": 1
    },
    {
      "id": "83e57764-c096-45fc-a475-0167caa7eeaf",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1136,
        -320
      ],
      "parameters": {
        "color": 3,
        "width": 256,
        "height": 256,
        "content": "## Get Message\n\nSearches Gmail by sender and subject. If Gmail finds nothing, or the mailbox you watch is not this Gmail account, nothing reaches the reply step. If it finds several, the reply step runs several times."
      },
      "typeVersion": 1
    },
    {
      "id": "4875fac3-0ca1-4d26-a116-3afcfe8477c9",
      "name": "Filter leads",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "notes": "Asks an AI model whether the message looks like a lead for your service. Expected answer: JSON with a lead value of true or false.",
      "position": [
        240,
        0
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "= Indicate if the following message is a lead that's interested in my YOUR_SERVICE_OR_OFFER\n\nOutput as JSON {\"lead\": \"<true/false>\"}\n\n {{ $json.textPlain }}"
            }
          ]
        },
        "jsonOutput": true
      },
      "notesInFlow": true,
      "typeVersion": 1.8
    },
    {
      "id": "7c5f6533-c82e-4fa2-b794-c93b38903c7c",
      "name": "Reply with customized message",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "notes": "Asks an AI model to write the reply from the message text. The reply is sent without review.",
      "position": [
        848,
        0
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "You're currently monitoring a sales email inbox for YOUR_BUSINESS_AND_SERVICE. For every inquiry you receive, read it and write a short reply tuned to that person. Use plain, no-frills language. Only use facts given here. Never promise a call, a callback, a price, a date or a link, and never invent any. Sign off as YOUR_NAME, YOUR_COMPANY."
            },
            {
              "content": "Hi, I run a small shop and I would like to know how your service works and what the first step is."
            },
            {
              "role": "assistant",
              "content": "Hello,\n\nThanks for getting in touch. In short: YOUR_ONE_LINE_DESCRIPTION. The first step is a short message from you describing what you need, and we reply by email with the next step.\n\nBest regards,\nYOUR_NAME, YOUR_COMPANY"
            },
            {
              "content": "={{ $('Email Trigger (IMAP)').item.json.textPlain }}"
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 1.8
    },
    {
      "id": "7b1e9c24-5d08-4a63-b2f7-3c80d1a46e95",
      "name": "Before you turn it on",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -48,
        -760
      ],
      "parameters": {
        "color": 3,
        "width": 1600,
        "height": 360,
        "content": "## Before you turn it on\n\n1. This replies to real people with text written by an AI and nobody reads it first. Use a test mailbox and your own addresses.\n2. There is no check for newsletters, automatic mail, mailing lists or other autoresponders, so two automatic senders can answer each other.\n3. The AI sees the full message text. A sender can write instructions into it.\n4. The AI can promise or invent things. The prompt in this file tells it not to, but check every reply.\n5. If the mailbox you watch is not the connected Gmail account, the search step finds nothing and no reply is sent.\n6. The same message can be answered more than once: the trigger does not mark mail as read, and the search step can match several messages.\n7. Sender names and message text go to the AI service and to Gmail.\n8. Not tested on live APIs."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Filter": {
      "main": [
        [
          {
            "node": "Reply with customized message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Message": {
      "main": [
        [
          {
            "node": "Reply to Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter leads": {
      "main": [
        [
          {
            "node": "Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email Trigger (IMAP)": {
      "main": [
        [
          {
            "node": "Filter leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reply with customized message": {
      "main": [
        [
          {
            "node": "Get Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}