{
  "id": "g9r4yBMwWxsupyjv",
  "name": "AI-Powered IMAP Monitor with Telegram Alerts and Smart Auto-Reply",
  "tags": [],
  "nodes": [
    {
      "id": "c12ebb83-47fd-470b-ba67-151e1b259b82",
      "name": "No Operation",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -688,
        704
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "3098bb59-a78d-4a8d-8253-466f98832ec0",
      "name": "Send Notification from Incoming Email",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -1376,
        464
      ],
      "parameters": {
        "text": "=\ud83d\udce7 **Incoming Email!**\n\n\ud83d\udc64 **Sender:** {{ $json.from }}\n\ud83d\udccc **Subject:** {{ $json.subject }}\n\ud83d\udcc5 **Date-Time:** {{ $json.date }}\n\n---\n_Automatic notification from IMAP (SOGo) mailbox_",
        "chatId": "=-1234567890123",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "45c29e94-e265-4853-a20d-60a1dc099ea8",
      "name": "Dedicate Filtering As No-Response",
      "type": "n8n-nodes-base.if",
      "position": [
        -1056,
        464
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.from.value[0].address }}",
              "value2": "noreply",
              "operation": "notContains"
            },
            {
              "value1": "={{ $json.from.value[0].address }}",
              "value2": "no-reply",
              "operation": "notContains"
            },
            {
              "value1": "={{ $json.subject.toLowerCase() }}",
              "value2": "newsletter",
              "operation": "notContains"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "78483eec-fc65-432b-9e7d-d41db7588647",
      "name": "Check Incoming Emails - IMAP (example: SOGo)",
      "type": "n8n-nodes-base.emailReadImap",
      "position": [
        -1664,
        464
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "imap": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "19549685-fc0a-4ed3-bcaf-8be2c946cb79",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2208,
        112
      ],
      "parameters": {
        "color": 4,
        "width": 508,
        "height": 216,
        "content": "## IMAP Email Monitor with Smart Auto-Reply\n\nAutomated email handling with three core functions:\n1. Monitors incoming emails via IMAP\n2. Sends instant Telegram notifications\n3. Auto-replies to legitimate emails while filtering spam\n\nFilters out noreply addresses and newsletters."
      },
      "typeVersion": 1
    },
    {
      "id": "1d5fe648-3529-41d2-a3c7-88e450be8461",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1776,
        624
      ],
      "parameters": {
        "width": 300,
        "height": 260,
        "content": "## IMAP CONFIGURATION\n\nRequires IMAP credential:\n- Host: IMAP server address\n- Port: Usually 993 for SSL/TLS\n- Username: Email address\n- Password: App-specific password\n- SSL/TLS: Enabled\n\nPolls mailbox at configured intervals."
      },
      "typeVersion": 1
    },
    {
      "id": "a03d2412-becc-4e7e-9bf3-e494177aa9db",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1488,
        208
      ],
      "parameters": {
        "width": 332,
        "height": 240,
        "content": "## TELEGRAM NOTIFICATION\n\nSends immediate notification for every new email.\n\nIncludes: Sender, Subject, Date-Time\n\nRequires:\n- Chat ID (update -1234567890123)\n- Telegram API credential from @BotFather"
      },
      "typeVersion": 1
    },
    {
      "id": "9ba3905c-85e1-41ed-999f-82b0d519a7f8",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1152,
        624
      ],
      "parameters": {
        "width": 296,
        "height": 260,
        "content": "## SPAM FILTERING LOGIC\n\nBlocks auto-replies from:\n- Addresses containing noreply or no-reply\n- Subjects containing newsletter\n\nTrue path: Send auto-reply\nFalse path: No operation\n\nCustomize conditions as needed."
      },
      "typeVersion": 1
    },
    {
      "id": "4b3795ef-d342-4818-a343-a18070c23132",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        96
      ],
      "parameters": {
        "width": 300,
        "height": 328,
        "content": "## AI-POWERED AUTO-REPLY\n\nSends personalized acknowledgment to legitimate senders.\n\nRequires SMTP credential:\n- Host: SMTP server (e.g., Postfix)\n- Port: 587 (STARTTLS) or 465 (SSL)\n- Credentials and secure connection\n\nUpdate fromEmail with your address.\nAuto-reply message generated by LLM based on email content."
      },
      "typeVersion": 1
    },
    {
      "id": "a94c5eae-23f7-46cd-87d5-ef3a9be65cf2",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2208,
        336
      ],
      "parameters": {
        "color": 4,
        "width": 396,
        "height": 240,
        "content": "## CREDENTIALS REQUIRED\n\n1. IMAP Credential - for email monitoring\n2. SMTP Credential - for sending auto-replies\n3. Telegram API - bot token from @BotFather\n4. Ollama API - for LLM model access\n\nAll credentials configured in n8n credential manager.\n\nUse app-specific passwords for enhanced security."
      },
      "typeVersion": 1
    },
    {
      "id": "0074dcf8-3b77-416b-912c-b1c91f42ad4c",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -480,
        48
      ],
      "parameters": {
        "width": 300,
        "height": 372,
        "content": "## AI RESPONSE GENERATION\n\nUses LLM to generate contextual auto-reply.\n\nReads email content and identifies main topic in 2-4 words.\n\nGenerates personalized response:\n- Thanks sender for message\n- Mentions specific topic\n- Promises personal follow-up\n\nPrompt engineering ensures consistent format."
      },
      "typeVersion": 1
    },
    {
      "id": "71246042-ba4d-4767-bf42-247ce4998014",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -480,
        800
      ],
      "parameters": {
        "width": 300,
        "height": 300,
        "content": "## OLLAMA MODEL CONFIGURATION\n\nRequires Ollama API credential.\n\nModel: llama3.1\nContext window: 4096 tokens\n\nInstall Ollama locally or use remote instance.\n\nEnsure model is downloaded:\nollama pull llama3.1"
      },
      "typeVersion": 1
    },
    {
      "id": "e3d171cc-c71a-4c82-acaf-1605e9ba38d3",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        272,
        640
      ],
      "parameters": {
        "width": 300,
        "height": 296,
        "content": "## RESPONSE CONFIRMATION\n\nSends Telegram notification after auto-reply is sent.\n\nIncludes:\n- Original sender and subject\n- Generated AI response text\n\nConfirms successful auto-reply delivery."
      },
      "typeVersion": 1
    },
    {
      "id": "82d9e05d-8cb2-46fb-9a05-825b6ab9cb85",
      "name": "Ollama Model",
      "type": "@n8n/n8n-nodes-langchain.lmOllama",
      "position": [
        -416,
        672
      ],
      "parameters": {
        "model": "llama3.1:bf230501",
        "options": {
          "numCtx": 4096
        }
      },
      "credentials": {
        "ollamaApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0c1d9daa-3981-4918-872b-d6e121f8d23c",
      "name": "Basic LLM Chain",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        -416,
        448
      ],
      "parameters": {
        "text": "=Read the original email and identify its main topic or subject in 2-4 words maximum.\n\nORIGINAL EMAIL:\n{{ $('IMAP Email').item.json.textPlain }}\n\nReturn only this response, filling in the [TOPIC]:\n\nDear Correspondent! \nThank you for your message regarding [TOPIC]. \nI will respond with a personal message as soon as possible. \nHave a nice day!\n\nRULES:\n- Replace [TOPIC] with 2-4 words summarizing the email subject\n- Keep it simple and generic (e.g., \"your inquiry\", \"the project\", \"your request\")\n- Return ONLY the email text above\n- Do NOT add explanations or extra content",
        "batching": {},
        "messages": {
          "messageValues": [
            {
              "message": "You are an email response assistant."
            }
          ]
        },
        "promptType": "define"
      },
      "executeOnce": true,
      "notesInFlow": false,
      "retryOnFail": false,
      "typeVersion": 1.7,
      "alwaysOutputData": false
    },
    {
      "id": "1905aad8-dcd2-49dc-83ea-c93f3b9d4737",
      "name": "Send Auto-Response in SMTP (example POSTFIX)",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        80,
        448
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "options": {
          "allowUnauthorizedCerts": true
        },
        "subject": "=Re: {{ $('Check Incoming Emails - IMAP (example: SOGo)').item.json.subject }}",
        "toEmail": "={{ $('Check Incoming Emails - IMAP (example: SOGo)').item.json.from }}",
        "fromEmail": "={{ $('Check Incoming Emails - IMAP (example: SOGo)').item.json.to }}"
      },
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "d3a996dd-465f-46c7-acdd-1d0d1358a8bb",
      "name": "Send Notification from Response",
      "type": "n8n-nodes-base.telegram",
      "position": [
        80,
        672
      ],
      "parameters": {
        "text": "=\ud83d\udce7 **Auto-Response Sent!**\n\n\ud83d\udc64 **Sender:** {{ $json.from }}\n\ud83d\udccc **Subject:** {{ $json.subject }}\n\ud83d\udcc5 **Date-Time:** {{ $json.date }}\n\n**Response:** {{ $('Basic LLM Chain').item.json.text }}\n",
        "chatId": "=-1234567890123",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "1b586248-021d-4cdd-bed4-86bf918e61aa",
  "connections": {
    "Ollama Model": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain": {
      "main": [
        [
          {
            "node": "Send Auto-Response in SMTP (example POSTFIX)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Dedicate Filtering As No-Response": {
      "main": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Notification from Incoming Email": {
      "main": [
        [
          {
            "node": "Dedicate Filtering As No-Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Incoming Emails - IMAP (example: SOGo)": {
      "main": [
        [
          {
            "node": "Send Notification from Incoming Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Auto-Response in SMTP (example POSTFIX)": {
      "main": [
        [
          {
            "node": "Send Notification from Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}