{
  "name": "AI Email Reply with n8n, Airtable and Gmail (free JSON)",
  "nodes": [
    {
      "id": "91c45a87-a5e7-4446-ad36-52b779a04ff5",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1680,
        704
      ],
      "parameters": {
        "text": "=You are an AI support agent for a B2B SaaS product from YOUR_COMPANY.\nYou receive many emails from customers and prospects every day: quote requests, technical questions, billing problems, bugs, requests for information about features.\nYour role is to answer them quickly, in a natural, friendly, clear, technical and very concise style.\n\nReply style\n\nThe reply must be very, very short (only the essentials, no useless chatter).\n\nAdapt to the customer's tone: if the customer is casual, be casual; if the customer is formal, be formal.\n\nBe friendly and human (as if writing to a colleague).\n\nBe technical when needed (give precise steps or direct solutions).\n\nAlways answer point by point the exact content of the email received.\n\nIf information is missing, ask 1 single clear question to move forward.\n\nReply structure\n\nPersonal greeting: say hello with the first name if possible.\n\nAcknowledgment: show that you understood the request.\n\nConcrete answer: give the solution or the next step directly.\n\nNext step: suggest one simple action (a test, a link, a detail to provide).\n\nFriendly closing: short and nice.\n\n\nID {{ $json.id }}\n\nTHREAD ID {{ $json.threadId }}\n\nSNIPPET {{ $json.snippet }}\n\nEMAIL {{ $json.From }}\n\nSUBJECT {{ $json.Subject }}\n\n\nPassword reset page: YOUR_PASSWORD_RESET_LINK",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "f10f7b53-8918-4c90-b7e8-8b573c01e78f",
      "name": "Email Received",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        1296,
        704
      ],
      "parameters": {
        "filters": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "222701be-af4e-441a-8c95-199c631c331a",
      "name": "GPT-4.1 Mini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1648,
        880
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "4972ea0f-8d5e-48eb-bb42-f00017a9d2ad",
      "name": "Save to Airtable",
      "type": "n8n-nodes-base.airtable",
      "position": [
        2160,
        704
      ],
      "parameters": {
        "base": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_AIRTABLE_BASE_ID"
        },
        "table": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_AIRTABLE_TABLE_ID"
        },
        "columns": {
          "value": {
            "Message": "={{ $('Email Received').item.json.snippet }}",
            "Subject": "={{ $('Email Received').item.json.Subject }}",
            "AI Response": "={{ $('AI Agent').item.json.output }}",
            "Customer Email": "={{ $('Email Received').item.json.From }}"
          },
          "schema": [
            {
              "id": "Subject",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Subject",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Date",
              "type": "dateTime",
              "display": true,
              "removed": true,
              "readOnly": false,
              "required": false,
              "displayName": "Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Customer Email",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Customer Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Message",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Message",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI Response",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "AI Response",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "create"
      },
      "typeVersion": 2.1
    },
    {
      "id": "3ae5bac1-4774-4daa-b516-a50492c5b3bc",
      "name": "Reply to Customer",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2592,
        704
      ],
      "parameters": {
        "message": "={{ $json.fields['AI Response'] }}",
        "options": {},
        "resource": "thread",
        "threadId": "={{ $('Email Received').item.json.id }}",
        "messageId": "={{ $('Email Received').item.json.id }}",
        "operation": "reply"
      },
      "typeVersion": 2.1
    },
    {
      "id": "d7d830d1-ea78-41f6-8261-aea5c7fb4dd4",
      "name": "Conversation Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1840,
        880
      ],
      "parameters": {
        "sessionKey": "={{ $('Email Received').item.json.id }}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "a7c1d4db-0539-4db9-8f98-59e250645e17",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        272,
        112
      ],
      "parameters": {
        "width": 928,
        "height": 912,
        "content": "## AI email reply with Airtable and Gmail\n\nFor each new email, an AI agent writes a short reply, the email and the reply are saved in an Airtable table, and the reply is sent in Gmail.\n\n### Setup\n1. Connect Gmail, Airtable and OpenAI credentials.\n2. Create an Airtable base with a table that has these fields: Subject, Date, Customer Email, Message, AI Response.\n3. Select your base and table in Save to Airtable.\n4. Edit the agent instructions: replace YOUR_COMPANY and YOUR_PASSWORD_RESET_LINK, and describe your own product.\n5. Test with your own addresses. Read the note Before you turn it on.\n\nSource: based on a template from the n8n Library at n8n.io, documented by LeenLabs. Not tested on live APIs."
      },
      "typeVersion": 1
    },
    {
      "id": "77461e99-0aab-4126-8019-424058945361",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1200,
        -560
      ],
      "parameters": {
        "color": 6,
        "width": 384,
        "height": 1584,
        "content": "## Email Received\n\nGmail Trigger, checked every minute, with no filter. It returns the full email data, not the simplified version. The text it gives the agent is only the short preview (snippet), not the whole message."
      },
      "typeVersion": 1
    },
    {
      "id": "f1d51f68-15fb-47b6-9ce2-0c64c1c41042",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1584,
        -560
      ],
      "parameters": {
        "color": 7,
        "width": 384,
        "height": 1584,
        "content": "## AI Agent\n\nWrites a short reply from the sender, subject and preview. Uses the GPT-4.1 Mini model and a memory node. The memory is keyed on the message id, so it does not link the messages of one conversation."
      },
      "typeVersion": 1
    },
    {
      "id": "cce445a1-0b91-4533-9e6a-b7ecff97d9a0",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1968,
        -560
      ],
      "parameters": {
        "color": 5,
        "width": 496,
        "height": 1584,
        "content": "## Save to Airtable\n\nAdds one row: Subject, Customer Email (the full From line), Message (the preview) and AI Response. The Date field is switched off in this node, so no date is written. The reply step only runs if this step succeeds."
      },
      "typeVersion": 1
    },
    {
      "id": "41d75e25-18db-4d52-bf1f-3799268e75b4",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2464,
        -560
      ],
      "parameters": {
        "color": 6,
        "width": 352,
        "height": 1584,
        "content": "## Reply to Customer\n\nReplies in Gmail with the text saved in Airtable. The message id is used as the thread id; this works for the first message of a conversation but may not for later ones. The reply is sent without review."
      },
      "typeVersion": 1
    },
    {
      "id": "3f6a8d12-7c45-49b0-a1e3-5d92b0c7f814",
      "name": "Before you turn it on",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        272,
        -352
      ],
      "parameters": {
        "color": 3,
        "width": 928,
        "height": 464,
        "content": "## Before you turn it on\n\n1. This replies to real people with AI text and nobody reads it first. Use a test mailbox and your own addresses.\n2. The trigger has no filter. Newsletters, spam and automatic mail get a reply too.\n3. Your own reply is a new message in the same mailbox. Check that it does not start the workflow again, or the agent may answer itself in a loop.\n4. The agent sees only the preview of each email, not the full text, so it can answer without knowing what was asked.\n5. The agent can invent facts and promises. The email text can also try to give it instructions.\n6. If Airtable fails, no reply is sent and nothing tells you.\n7. Email content goes to OpenAI, Airtable and Google.\n8. Not tested on live APIs."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Save to Airtable",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email Received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save to Airtable": {
      "main": [
        [
          {
            "node": "Reply to Customer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Conversation Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "GPT-4.1 Mini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {}
}