8
n8n 中文网amn8n.com

预定义个性化邮件工作流

中级

这是一个Lead Nurturing领域的自动化工作流,包含 12 个节点。主要使用 Set, Code, Wait, Limit, Merge 等节点。 使用SendGrid从Google Sheets向潜在客户发送预定义个性化邮件

前置要求
  • Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "bRqE6ZhtVXke3fyU",
  "meta": {
    "instanceId": "448c56269fcb937a399af90b22ef2e8d621aabeafc076e182e1b9fa079617f8e",
    "templateCredsSetupCompleted": true
  },
  "name": "预定义个性化邮件工作流",
  "tags": [],
  "nodes": [
    {
      "id": "ac2e7948-6d2e-4e6c-9dea-bb536c284bd1",
      "name": "当点击\"执行工作流\"时",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -1376,
        -224
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "ce1155a0-de1c-49e3-ad62-332d80591259",
      "name": "遍历项目",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -704,
        -224
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "7ba408be-13d0-4b97-8953-b979cee79622",
      "name": "合并",
      "type": "n8n-nodes-base.merge",
      "position": [
        -32,
        -288
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.2,
      "alwaysOutputData": false
    },
    {
      "id": "4d002700-b772-4134-b356-e321a667baeb",
      "name": "等待",
      "type": "n8n-nodes-base.wait",
      "position": [
        640,
        -224
      ],
      "webhookId": "376505fe-eed2-47a4-b973-8f7b7f22d8f4",
      "parameters": {
        "amount": 1
      },
      "typeVersion": 1.1
    },
    {
      "id": "75427d7b-8904-41f3-b0e5-214864fc5471",
      "name": "从数据库解析邮件模板",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -480,
        -224
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 449875511,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1UGarQNCplIfKKPSInxZlIC72oosZ45ul5jAQjYfpWrs/edit#gid=449875511",
          "cachedResultName": "Email Template"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1UGarQNCplIfKKPSInxZlIC72oosZ45ul5jAQjYfpWrs",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1UGarQNCplIfKKPSInxZlIC72oosZ45ul5jAQjYfpWrs/edit?usp=drivesdk",
          "cachedResultName": "Leads & Email Template"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LoM2gsoGsu6EqTU3",
          "name": "Google Sheets account 2"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "07fc2e28-3552-4169-9e00-a40962587694",
      "name": "随机选择一个模板",
      "type": "n8n-nodes-base.code",
      "position": [
        -256,
        -224
      ],
      "parameters": {
        "jsCode": "// Get templates from previous node\nconst templates = items.map(item => item.json);\n\n// Check if templates exist\nif (!templates || templates.length === 0) {\n  throw new Error('No templates found');\n}\n\n// Pick a random template\nconst index = Math.floor(Math.random() * templates.length);\nconst template = templates[index];\n\n// Convert body to HTML\nconst bodyHtml = template.Body.replace(/\\n/g, '<br>');\n\n// Return in n8n-compatible format\nreturn [\n  {\n    json: {\n      subject: template.Subject,\n      body: bodyHtml\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "04898505-3810-454d-a874-ed0c0b7abc1f",
      "name": "限制",
      "type": "n8n-nodes-base.limit",
      "position": [
        -928,
        -224
      ],
      "parameters": {
        "maxItems": 20
      },
      "typeVersion": 1
    },
    {
      "id": "9a0b6308-74f9-4b6e-aaa2-9b6171e7cef6",
      "name": "获取表格中的行",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -1152,
        -224
      ],
      "parameters": {
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "51cb6840-cf3d-46c7-a155-c0a6c1571d7c",
      "name": "发送邮件",
      "type": "n8n-nodes-base.sendGrid",
      "onError": "continueRegularOutput",
      "position": [
        416,
        -288
      ],
      "parameters": {
        "subject": "={{ $json.subject }}",
        "toEmail": "={{ $json.email }}",
        "resource": "mail",
        "contentType": "text/html",
        "contentValue": "={{ $json.body }}",
        "additionalFields": {
          "replyToEmail": ""
        }
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "8e899e27-9aea-4eb5-9e66-433be11268e9",
      "name": "修复变量",
      "type": "n8n-nodes-base.set",
      "position": [
        192,
        -288
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "49a9d2c6-d9b3-4548-b00d-f74e2e999ebf",
              "name": "body",
              "type": "string",
              "value": "={{ \n$json.body\n    .replaceAll(\"[BusinessName]\", $json[\"Business Name\"]?.trim() || \"your restaurant\")\n    .replaceAll(\"[Category]\", $json[\"Category\"]?.trim() || \"restaurant\")\n    .replaceAll(\"[Location]\", $json[\"Location\"]?.trim() || \"your area\")\n    .replaceAll(\"[OtherCategories]\", $json[\"Other Categories\"]?.trim() || \"similar restaurants\")\n}}"
            },
            {
              "id": "25e35314-0fdb-40bc-9d81-a025eff70010",
              "name": "subject",
              "type": "string",
              "value": "={{ \n$json.subject\n    .replaceAll(\"[BusinessName]\", $json[\"Business Name\"]?.trim() || \"your restaurant\")\n    .replaceAll(\"[Category]\", $json[\"Category\"]?.trim() || \"restaurant\")\n    .replaceAll(\"[Location]\", $json[\"Location\"]?.trim() || \"your area\")\n    .replaceAll(\"[OtherCategories]\", $json[\"Other Categories\"]?.trim() || \"similar restaurants\")\n}}"
            },
            {
              "id": "eec4abbb-c30f-4aa3-99a3-6045b80eee68",
              "name": "email",
              "type": "string",
              "value": "={{ $json.Email }}"
            },
            {
              "id": "19db0a1f-6c61-4452-8bd0-0ddac9b1b919",
              "name": "ID",
              "type": "string",
              "value": "={{ $json.ID }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "8ebfe20b-4238-4e55-9066-1802265f7f76",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1424,
        -880
      ],
      "parameters": {
        "color": 3,
        "width": 784,
        "height": 608,
        "content": "## 📧 使用 SendGrid 和预定义邮件模板的邮件工作流"
      },
      "typeVersion": 1
    },
    {
      "id": "d8ff919b-9064-46d4-aa88-b589ce134ed4",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        208,
        -816
      ],
      "parameters": {
        "color": 4,
        "width": 480,
        "height": 464,
        "content": "## 🧩 进一步扩展此工作流"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "a0312591-5e32-4569-8767-492541575714",
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limit": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Fix Variables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fix Variables": {
      "main": [
        [
          {
            "node": "Send an email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send an email": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Parse Email Template from DB",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet": {
      "main": [
        [
          {
            "node": "Limit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pick a random template": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Parse Email Template from DB": {
      "main": [
        [
          {
            "node": "Pick a random template",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 客户培育

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量12
分类1
节点类型10
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
Ezema Kingsley Chibuzo

Ezema Kingsley Chibuzo

@kingsley

Data Analyst, Automation Developer, and AI Workflow Specialist with experience designing end-to-end systems using n8n and its integrations. I help businesses unlock insights, automate operations, and scale with custom AI-powered workflows, dynamic dashboards, and no-code tools. My work combines strong analytical thinking with smart automation — from data collection and enrichment to lead generation, reporting, and AI agent orchestration. Here’s my contact below if you’d like to connect with me:

外部链接
在 n8n.io 查看

分享此工作流