AutomationFlowsAI & RAG › N8n AI Mail Sender

N8n AI Mail Sender

n8n-ai-mail-sender. Uses telegram, agent, lmChatGroq, outputParserStructured. Event-driven trigger; 14 nodes.

Event trigger★★★★☆ complexityAI-powered14 nodesTelegramAgentGroq ChatOutput Parser StructuredGmailGoogle SheetsGmail Trigger
AI & RAG Trigger: Event Nodes: 14 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow follows the Agent → Gmail recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "name": "n8n-ai-mail-sender",
  "nodes": [
    {
      "parameters": {
        "chatId": "-1003031215155",
        "text": "=\u041d\u043e\u0432\u044b\u0439 \u043a\u043b\u0438\u0435\u043d\u0442: {{ $('Waiting for answer').item.json.From }}\n\u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435: {{ $json.cleaned_text }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        288,
        208
      ],
      "id": "082ebf8b-3eb0-4a30-9691-f1d76c38ba6f",
      "name": "Send a text message",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "language": "python",
        "pythonCode": "import re\n\ntext = _input.first().json.get(\"snippet\", \"\")\n\n#pattern = r\"\\b(?:\u043f\u043d|\u0432\u0442|\u0441\u0440|\u0447\u0442|\u043f\u0442|\u0441\u0431|\u0432\u0441|mo|di|mi|do|fr|sa|so|mo|tu|we|th|fr|sa|su),\\s\\d{1,2}\\s[\u0430-\u044f]{3,}\\.\\s\\d{4}\\s\u0433\\.\\s\u0432\\s\\d{1,2}:\\d{2}\"\n\npattern = r\"\\b(?:\u043f\u043d|\u0432\u0442|\u0441\u0440|\u0447\u0442|\u043f\u0442|\u0441\u0431|\u0432\u0441|mo|di|mi|do|fr|sa|so|mon|tue|wed|thu|fri|sat|sun),?\\s*\\d{1,2}\\s+(?:\u044f\u043d\u0432|\u0444\u0435\u0432|\u043c\u0430\u0440|\u0430\u043f\u0440|\u043c\u0430\u0439|\u0438\u044e\u043d|\u0438\u044e\u043b|\u0430\u0432\u0433|\u0441\u0435\u043d|\u043e\u043a\u0442|\u043d\u043e\u044f|\u0434\u0435\u043a|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec|jan|feb|m\u00e4r|apr|mai|jun|jul|aug|sep|okt|nov|dez)\\.?\\s+\\d{4}(?:\\s*(\u0433\\.|j\\.|y\\.|year|jahr))?\\s*(\u0432\\s|um\\s|at\\s)?\\d{1,2}:\\d{2}\"\n\nmatch = re.search(pattern, text)\n\nif match:\n    cleaned_text = text[:match.start()].strip()\nelse:\n    cleaned_text = text.strip()\n\nreturn [{\n    \"json\": {\n        \"cleaned_text\": cleaned_text\n    }\n}]\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        16,
        208
      ],
      "id": "c02d4690-91cd-48a1-8a26-94b30eac911c",
      "name": "Messege_cleaner"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        112,
        -192
      ],
      "id": "c50114c3-8e37-4144-a06c-03e2ec4d8d3b",
      "name": "Loop Over Items"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -320,
        -192
      ],
      "id": "8861a8fc-be25-4b4a-87c5-181f08afa49c",
      "name": "When clicking \u2018Execute workflow\u2019"
    },
    {
      "parameters": {
        "jsCode": "const rows = items; // \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0443\u0437\u043b\u0430 (Google Sheets)\n\nconst firstUnsentRow = rows.find(row => !row.json[\"\u0421\u0442\u0430\u0442\u0443\u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438\"]); // \u0418\u0449\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0430\u0442\u0443\u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u0443\u0441\u0442\u043e\u0439\n\nif (firstUnsentRow) {\n  // \u0415\u0441\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u043d\u0430\u0439\u0434\u0435\u043d\u0430, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0435\u0451\n  return [{ json: firstUnsentRow.json }];\n} else {\n  // \u0415\u0441\u043b\u0438 \u0441\u0442\u0440\u043e\u043a \u043d\u0435\u0442 \u0441 \u043f\u0443\u0441\u0442\u044b\u043c \u0441\u0442\u0430\u0442\u0443\u0441\u043e\u043c, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u0443\u0441\u0442\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\n  return [];\n}\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        304,
        -176
      ],
      "id": "51b09a72-8631-473b-8eb2-708307b976b5",
      "name": "Code1"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Verfassen Sie eine kurze (max.\u00a0600\u00a0Zeichen im Flie\u00dftext) und professionelle E\u2011Mail auf Deutsch, adressiert an die Inhaber\u00b7innen einer Pizzeria. Der Ton soll locker, \u00fcberzeugend, modern und h\u00f6flich sein \u2013 eine Mischung aus Business und Social\u00a0Media.\n\nVerwenden Sie das folgende HTML\u2011Ger\u00fcst als Leitfaden: Schreiben Sie ausschlie\u00dflich HTML, bestehend aus zusammenh\u00e4ngenden <p>-Abs\u00e4tzen f\u00fcr jede Aussage. Beschreiben Sie in ein, zwei S\u00e4tzen, wer wir sind (Vegan Food) und warum unsere veganen Pizzen so erfolgreich sind. Anschlie\u00dfend listen Sie die wichtigsten Vorteile einer Partnerschaft mit uns als Aufz\u00e4hlung; verwenden Sie daf\u00fcr moderne Bullet\u00a0Points mit dem Emoji \u201e\ud83d\udc49\u201c \u2013 jede Zeile soll ein eigener <p>-Absatz sein. Beispielinhalte f\u00fcr die Aufz\u00e4hlung k\u00f6nnen sein:\n- Mehr Umsatz ohne zus\u00e4tzliche Kosten,\n- 85\u202f% des Bestellwerts f\u00fcr den Partner,\n- Exklusives Liefergebiet und exklusive Beilagen,\n- Produkte nicht im freien Handel erh\u00e4ltlich,\n- Wir bringen vegane Kunden durch gezieltes Marketing,\n- Komplettes Onboarding inklusive Lieferando\u2011Integration.\n\nBeenden Sie den Text einem freundlichen Aufruf zur Kontaktaufnahme. **Geben Sie nur den HTML\u2011Code zur\u00fcck** (kein <subject>, kein Footer, keine Kommentare). Ersetzen Sie das urspr\u00fcngliche <ul><li>\u2026</li></ul> vollst\u00e4ndig durch die oben beschriebenen <p>\u2011Bullet\u2011Points.\n",
        "hasOutputParser": true,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.8,
      "position": [
        720,
        -176
      ],
      "id": "dc7b56de-f2b3-4c7f-877b-bd9ed39c02ec",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "model": "llama-3.1-8b-instant",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "typeVersion": 1,
      "position": [
        720,
        96
      ],
      "id": "46d09df0-8e47-46c5-bdde-f36b37ecd78a",
      "name": "Groq Chat Model",
      "credentials": {
        "groqApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {},
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        896,
        32
      ],
      "id": "2981aec9-6ad0-40a0-bdfc-4c56103179ea",
      "name": "Structured Output Parser"
    },
    {
      "parameters": {
        "language": "python",
        "pythonCode": "# \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b\ninputs = _input.all()\n\n# \u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u0438\u0437 \u0432\u0445\u043e\u0434\u043e\u0432\ndata = {}\nfor item in inputs:\n    data.update(item.json)\n\n# \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\nemail_subject = data.get(\"email_subject\", \"\").strip()\nemail_footer_html = data.get(\"email_footer_html\", \"\").strip()\n#email_main_html = data.get(\"output\", \"\").strip()\nemail_main_html = data.get(\"main_text\", \"\").strip()\nvorteile_html = data.get(\"vorteile_text\", \"\").strip()\n\n# \u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 HTML\nemail_body_html = f\"\"\"<!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"UTF-8\">\n  <style>\n    body {{\n      font-family: Arial, sans-serif;\n      line-height: 1.5;\n      color: #333;\n    }}\n    a {{\n      color: #1a73e8;\n      text-decoration: none;\n    }}\n  </style>\n</head>\n<body>\n  {email_main_html}\n  {vorteile_html}\n  <hr style=\"margin: 30px 0; border: none; border-top: 1px solid #ccc;\" />\n  {email_footer_html}\n</body>\n</html>\n\"\"\"\n\n# \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\nreturn [{\n    \"json\": {\n        \"email_subject\": email_subject,\n        \"email_body_html\": email_body_html\n    }\n}]\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1104,
        -176
      ],
      "id": "fefd39bc-dd1b-4a4e-b144-6793c06ab004",
      "name": "mail_w"
    },
    {
      "parameters": {
        "sendTo": "={{ $('Chek status').first().json.emails }}",
        "subject": "={{ $json.email_subject }}",
        "message": "={{ $json.email_body_html }}",
        "options": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1312,
        -176
      ],
      "id": "1e4695ff-f3c0-40eb-bede-3599a7cba633",
      "name": "send mail",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1gjre4zRZw_3ViwQoSD9srER7id2npSaa7pTP1TnvgdE",
          "mode": "list",
          "cachedResultName": "Andrey_Emails",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gjre4zRZw_3ViwQoSD9srER7id2npSaa7pTP1TnvgdE/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "\u041b\u0438\u0441\u04421",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gjre4zRZw_3ViwQoSD9srER7id2npSaa7pTP1TnvgdE/edit#gid=0"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "\u0421\u0442\u0430\u0442\u0443\u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438",
              "lookupValue": "="
            }
          ]
        },
        "options": {
          "returnFirstMatch": false
        }
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.6,
      "position": [
        -144,
        -192
      ],
      "id": "e7ccf16e-f3a8-43dc-b5a3-8d38e5198ac4",
      "name": "get email",
      "executeOnce": false,
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1gjre4zRZw_3ViwQoSD9srER7id2npSaa7pTP1TnvgdE",
          "mode": "list",
          "cachedResultName": "Andrey_Emails",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gjre4zRZw_3ViwQoSD9srER7id2npSaa7pTP1TnvgdE/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "\u041b\u0438\u0441\u04421",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gjre4zRZw_3ViwQoSD9srER7id2npSaa7pTP1TnvgdE/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "emails": "={{ $('get email').item.json.emails }}",
            "\u0421\u0442\u0430\u0442\u0443\u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438": "1"
          },
          "matchingColumns": [
            "emails"
          ],
          "schema": [
            {
              "id": "emails",
              "displayName": "emails",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "\u0421\u0442\u0430\u0442\u0443\u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438",
              "displayName": "\u0421\u0442\u0430\u0442\u0443\u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": true,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.6,
      "position": [
        480,
        -176
      ],
      "id": "39f357de-8c93-4e68-8983-b3e9a7efae84",
      "name": "Chek status",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1gjre4zRZw_3ViwQoSD9srER7id2npSaa7pTP1TnvgdE",
          "mode": "list",
          "cachedResultName": "Andrey_Emails",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gjre4zRZw_3ViwQoSD9srER7id2npSaa7pTP1TnvgdE/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "\u041b\u0438\u0441\u04421",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gjre4zRZw_3ViwQoSD9srER7id2npSaa7pTP1TnvgdE/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "emails": "={{ $('get email').item.json.emails }}",
            "\u0421\u0442\u0430\u0442\u0443\u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438": "2"
          },
          "matchingColumns": [
            "emails"
          ],
          "schema": [
            {
              "id": "emails",
              "displayName": "emails",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "\u0421\u0442\u0430\u0442\u0443\u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438",
              "displayName": "\u0421\u0442\u0430\u0442\u0443\u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": true,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.6,
      "position": [
        336,
        -336
      ],
      "id": "d7c155de-d732-46dc-b7a7-43f0579c3dbf",
      "name": "Set status",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "filters": {}
      },
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.3,
      "position": [
        -288,
        208
      ],
      "id": "f7d26b65-b256-44bf-b322-5a2813de53b2",
      "name": "Waiting for answer",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Messege_cleaner": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Set status",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Code1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "get email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code1": {
      "main": [
        [
          {
            "node": "Chek status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Groq Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "mail_w",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "mail_w": {
      "main": [
        [
          {
            "node": "send mail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "send mail": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get email": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chek status": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Waiting for answer": {
      "main": [
        [
          {
            "node": "Messege_cleaner",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "928f0a95-3a60-4d00-8dba-e989eaea1d3e",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "dvHcsFVonBaQCN9s",
  "tags": []
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

n8n-ai-mail-sender. Uses telegram, agent, lmChatGroq, outputParserStructured. Event-driven trigger; 14 nodes.

Source: https://github.com/litus-work/n8n-ai-mail-sender/blob/5368f7cb29e66b1f9a77deffb8604e9213b3bfbb/n8n-ai-mail-sender.json — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

Multi-Channel Email Intelligence Agent. Uses lmChatOpenAi, outputParserStructured, gmailTrigger, agent. Event-driven trigger; 18 nodes.

OpenAI Chat, Output Parser Structured, Gmail Trigger +6
AI & RAG

ITfest. Uses telegramTrigger, telegram, textClassifier, agent. Event-driven trigger; 70 nodes.

Telegram Trigger, Telegram, Text Classifier +6
AI & RAG

Inbox Guardian. Uses gmailTrigger, lmChatOpenAi, agent, textClassifier. Event-driven trigger; 66 nodes.

Gmail Trigger, OpenAI Chat, Agent +12
AI & RAG

An AI-powered Gmail assistant built with n8n that automatically labels emails, learns from your decisions, and safely improves over time using human-in-the-loop training.

Agent, Output Parser Structured, OpenAI Chat +6
AI & RAG

This n8n workflow automates your entire B2B outreach pipeline from lead discovery to personalized cold email delivery. Submit a form, let Apollo find and enrich your leads, review AI-generated emails

Output Parser Structured, Agent, Groq Chat +4