8
n8n 中文网amn8n.com

Gmail发件人联系人自动添加至MySQL数据库

中级

这是一个Lead Generation领域的自动化工作流,包含 7 个节点。主要使用 Code, MySql, GmailTrigger 等节点。 Gmail发件人联系人自动添加至MySQL数据库

前置要求
  • MySQL 数据库连接信息
  • Google 账号和 Gmail API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "d6e2f2f655b1125bbcac14a4cac6d2e46c7a150e927f85fc96fdca1a6dc39e0e",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "c6250c78-41e1-4977-8f3b-d34a76a24f82",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        140,
        -340
      ],
      "parameters": {
        "height": 1480,
        "content": "## 此工作流处理在 Gmail 中收到的电子邮件,并将发件人的**姓名**和**电子邮件地址**添加到 MySQL 数据库。"
      },
      "typeVersion": 1
    },
    {
      "id": "3688fcda-44ad-47c1-bc76-3f3fa04ca436",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        960,
        -80
      ],
      "parameters": {
        "width": 300,
        "height": 680,
        "content": "## 请先设置此节点"
      },
      "typeVersion": 1
    },
    {
      "id": "1cbe3946-6b48-483e-9983-2f0c3f243c40",
      "name": "在 MySQL 中插入新客户",
      "type": "n8n-nodes-base.mySql",
      "onError": "continueRegularOutput",
      "position": [
        1040,
        200
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "contacts",
          "cachedResultName": "contacts"
        },
        "options": {},
        "dataMode": "defineBelow",
        "operation": "upsert",
        "valuesToSend": {
          "values": [
            {
              "value": "={{ $json.name }}",
              "column": "name"
            }
          ]
        },
        "valueToMatchOn": "={{ $json.email }}",
        "columnToMatchOn": "email"
      },
      "credentials": {
        "mySql": {
          "id": "MYdqb2i2fz5O21ui",
          "name": "BT Operations Database"
        }
      },
      "typeVersion": 2.4,
      "alwaysOutputData": true
    },
    {
      "id": "ff005111-3172-4022-92b1-9280458d6741",
      "name": "接收电子邮件",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        500,
        200
      ],
      "parameters": {
        "filters": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "YVZiLPppXZw84rIU",
          "name": "Gmail account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "5a266f76-1c4d-48ed-a50b-65998cfe135c",
      "name": "提取客户姓名和电子邮件",
      "type": "n8n-nodes-base.code",
      "position": [
        760,
        200
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "let email = $json.From.trim();\nlet name = null;\n\nif (email.includes('<')) {\n  name = email.split('<')[0].trim();\n  email = email.split('<')[1].replace('>', '').trim();\n}\n\nreturn {\n  \"name\": name,\n  \"email\": email\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "0b4cf2a9-e890-4561-a6c5-e0c85838a777",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        440,
        -80
      ],
      "parameters": {
        "color": 5,
        "height": 460,
        "content": "## 根据您的喜好自定义此节点"
      },
      "typeVersion": 1
    },
    {
      "id": "58e5e9bd-3bf7-4c3a-80be-c4ac2ff0f370",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1280,
        -20
      ],
      "parameters": {
        "color": 5,
        "height": 420,
        "content": "## 自定义此工作流:"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "Receive Email": {
      "main": [
        [
          {
            "node": "Extract Client Name and Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Client Name and Email": {
      "main": [
        [
          {
            "node": "Insert New Client in MySQL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 潜在客户开发

需要付费吗?

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

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

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

外部链接
在 n8n.io 查看

分享此工作流