8
n8n 中文网amn8n.com

使用 AI、Gmail 和 Google Sheets 自动化每周宠物健康邮件

高级

这是一个自动化工作流,包含 19 个节点。主要使用 Code, Wait, Gmail, SendGrid, GoogleSheets 等节点。 使用 GPT-4o-mini、Gmail 和 Google Sheets 发送每周个性化宠物健康提示

前置要求
  • Google 账号和 Gmail API 凭证
  • Google Sheets API 凭证
  • OpenAI API Key

分类

-
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "YV9jJYlu5axheX09",
  "meta": {
    "instanceId": "506e1eb999b7a8cf86103921b3e1b94e371534d9bae39d44754933678dc6697d"
  },
  "name": "使用 AI、Gmail 和 Google Sheets 自动化每周宠物健康邮件",
  "tags": [
    {
      "id": "T3xhK1cIuPex0boX",
      "name": "Templates",
      "createdAt": "2025-09-03T11:06:03.839Z",
      "updatedAt": "2025-09-03T11:06:03.839Z"
    }
  ],
  "nodes": [
    {
      "id": "a1cb38ea-5319-4042-84e6-caad7bd27e8f",
      "name": "生成个性化提示",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        1328,
        80
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "GPT-4O-MINI"
        },
        "options": {
          "temperature": 0.7
        },
        "messages": {
          "values": [
            {
              "content": "=Generate a personalized pet care tip for:\n- Pet name: {{ $json.Pet_Name }}\n- Pet type: {{ $json.Pet_Type }}\n- Pet age: {{ $json.pet_age_months }} months\n- Location: Country ISO is {{ $json['Country (ISO)'] }}\n- Current date: {{ $now.format('MMMM YYYY') }}\n\nRequirements:\n- Veterinary-aligned and breed-appropriate advice\n- **Climate-specific** (consider hemisphere, season in {{ $json['Country (ISO)'] }})\n- Region-specific risks (parasites, weather hazards)\n- Actionable advice (2-3 sentences)\n- Brief headline (under 10 words)\n- Life stage: puppy/kitten (<12mo), adult (1-7yr), senior (7+yr)\n\nExamples:\n- UK October: rain gear, indoor exercise, fireworks anxiety\n- Australia October: spring heat, snake awareness, hydration\n- Canada October: early cold prep, paw protection\n\nFormat as JSON:\n{\n  \"topic\": \"Brief topic title\",\n  \"headline\": \"Engaging headline for {{ $json.Pet_Name }}\",\n  \"content\": \"2-3 sentence tip with location-specific advice\",\n  \"category\": \"Nutrition/Exercise/Health/Behavior/Safety\"\n}"
            },
            {
              "role": "system",
              "content": "=You are a veterinary wellness expert providing evidence-based weekly tips for pet owners.\n\nGuidelines:\n- Align with AAHA/WSAVA veterinary standards\n- Tailor advice to pet type and life stage\n- Include seasonal considerations ({{ $now.format('MMMM') }})\n- Be warm but professional\n- Always recommend vet consultation for medical concerns"
            }
          ]
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "mvWns3smwtPV0N7O",
          "name": "OpenAI (Dummy Account)"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "1703951c-551a-4f84-9aad-3d1a1fec6144",
      "name": "无操作,不执行任何操作",
      "type": "n8n-nodes-base.noOp",
      "position": [
        1104,
        -112
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "b454fd2e-7690-45a8-9bd1-f30138c822c8",
      "name": "计算宠物年龄",
      "type": "n8n-nodes-base.code",
      "position": [
        1104,
        80
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\n\nreturn items.map(item => {\n  const birthDate = new Date(item.json.Date_of_Birth);\n  const ageInMs = Date.now() - birthDate;\n  const ageMonths = Math.floor(ageInMs / (1000 * 60 * 60 * 24 * 30.44));\n  const ageYears = Math.floor(ageMonths / 12);\n  const remainingMonths = ageMonths % 12;\n  \n  let petAge;\n  if (ageMonths < 12) {\n    petAge = `${ageMonths} month${ageMonths !== 1 ? 's' : ''}`;\n  } else if (remainingMonths === 0) {\n    petAge = `${ageYears} year${ageYears !== 1 ? 's' : ''}`;\n  } else {\n    petAge = `${ageYears} year${ageYears !== 1 ? 's' : ''} and ${remainingMonths} month${remainingMonths !== 1 ? 's' : ''}`;\n  }\n  \n  return {\n    json: {\n      ...item.json,\n      pet_age_months: ageMonths,\n      pet_age: petAge\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "1ab3dd7f-bb4a-4c00-b21f-7df710e66a67",
      "name": "使用 Gmail 发送健康提示",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1904,
        80
      ],
      "webhookId": "dd40acbc-8a2c-417b-9767-3f49f71d9e76",
      "parameters": {
        "sendTo": "={{ $json.email }}",
        "message": "=<p>Hi {{ $json.owner_name }},</p>\n\n<h3>{{ $json.tip_headline }}</h3>\n\n<p>{{ $json.tip_content }}</p>\n\n\n<p>Stay pawsitive! 🐾<br>\n<em>PetCare Team</em></p>",
        "options": {
          "senderName": "PetCare Team",
          "appendAttribution": false
        },
        "subject": "={{ $json.tip_headline }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "eyfJ66dKQb9DbBvR",
          "name": "Gmail (Dummy Account)"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "d68799f3-e768-4139-b8d9-68fc1fd9a657",
      "name": "每周触发器(周一上午9点)",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        208,
        80
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtDay": [
                1
              ],
              "triggerAtHour": 9
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "0aaeebf6-69fb-4acd-a70a-2920d3188345",
      "name": "过滤器:活跃 + 7天检查",
      "type": "n8n-nodes-base.code",
      "position": [
        656,
        80
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\n\nreturn items.filter(item => {\n  // Must be Active status\n  if (item.json.Status !== 'Active') return false;\n  \n  // Never sent email = include\n  if (!item.json.Last_Email_Sent) return true;\n  \n  // Sent >7 days ago = include\n  const daysSince = (Date.now() - new Date(item.json.Last_Email_Sent)) / (1000*60*60*24);\n  return daysSince > 7;\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "b74fedec-acdf-400d-b2e7-0b9aab4f3044",
      "name": "逐个处理宠物",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        880,
        80
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "ca404c94-1c4b-4a42-b2e2-b244c3e66873",
      "name": "格式化邮件数据",
      "type": "n8n-nodes-base.code",
      "position": [
        1680,
        80
      ],
      "parameters": {
        "jsCode": "// Get pet data from Calculate Pet Age node\nconst petData = $('Calculate Pet Age').item.json;\nconst aiResponse = $json.message.content;\n\nconst cleanResponse = aiResponse.replace(/```json\\n?/g, '').replace(/```\\n?/g, '').trim();\n\nlet tipData;\ntry {\n  tipData = JSON.parse(cleanResponse);\n} catch (e) {\n  tipData = {\n    topic: 'Weekly Pet Care Tip',\n    headline: `Important advice for ${petData.Pet_Name}`,\n    content: cleanResponse,\n    category: 'General'\n  };\n}\n\nreturn {\n  json: {\n    email: petData.Email,\n    owner_name: petData.Owner_Name,\n    pet_name: petData.Pet_Name,\n    pet_type: petData.Pet_Type,\n    pet_age: petData.pet_age,\n    pet_age_months: petData.pet_age_months,\n    tip_topic: tipData.topic,\n    tip_headline: tipData.headline,\n    tip_content: tipData.content,\n    tip_category: tipData.category,\n    row_number: petData.row_number\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "4d490b67-69ff-453d-9916-fd9ad3a43c2e",
      "name": "通过 SendGrid 发送(已禁用)",
      "type": "n8n-nodes-base.sendGrid",
      "disabled": true,
      "position": [
        1888,
        -144
      ],
      "parameters": {
        "toEmail": "={{ $json.email }}",
        "fromName": "PetCare Team",
        "resource": "mail",
        "fromEmail": "hello@petcareteam.com",
        "templateId": "=d-xxxxxx",
        "dynamicTemplate": true,
        "additionalFields": {},
        "dynamicTemplateFields": {
          "fields": [
            {
              "key": "owner_name",
              "value": "={{ $json.owner_name }}"
            },
            {
              "key": "pet_name",
              "value": "= {{ $json.pet_name }}"
            },
            {
              "key": "tip_topic",
              "value": "={{ $json.tip_topic }}"
            },
            {
              "key": "tip_headline",
              "value": "={{ $json.tip_headline }}"
            },
            {
              "key": "tip_content",
              "value": "={{ $json.tip_content }}"
            },
            {
              "key": "tip_category",
              "value": "={{ $json.tip_category }}"
            },
            {
              "key": "pet_type",
              "value": "={{ $json.pet_type }}"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5875181b-6e58-46e6-9c48-569e6aad9130",
      "name": "更新最后发送邮件日期",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2128,
        80
      ],
      "parameters": {
        "columns": {
          "value": {
            "Email": "={{ $('Format Email Data').item.json.email }}",
            "Last_Email_Sent": "={{$now}}"
          },
          "schema": [
            {
              "id": "Email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Owner_Name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Owner_Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Pet_Name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Pet_Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Country (ISO)",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Country (ISO)",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Pet_Type",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Pet_Type",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Date_of_Birth",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Date_of_Birth",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Last_Email_Sent",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Last_Email_Sent",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Email"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1625335217,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1qd1H_IY_KEtB1C-ZJzpdmw9_yQEqdpnrf4ZdlV02gW4/edit#gid=1625335217",
          "cachedResultName": "Pets"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1qd1H_IY_KEtB1C-ZJzpdmw9_yQEqdpnrf4ZdlV02gW4",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1qd1H_IY_KEtB1C-ZJzpdmw9_yQEqdpnrf4ZdlV02gW4/edit?usp=drivesdk",
          "cachedResultName": "N8N SHEETS TEST"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "zyEOPkCfmHTXNm4V",
          "name": "Google Sheets (Dummy Account)"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "0dc11fbc-448d-467e-8957-82887556d9bd",
      "name": "记录到邮件日志工作表",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2352,
        80
      ],
      "parameters": {
        "columns": {
          "value": {
            "Status": "={{ $('Send Health Tip using Gmail').item.json.labelIds[0] }}",
            "Pet_Name": "={{ $('Format Email Data').item.json.pet_name }}",
            "Timestamp": "={{ $now }}",
            "Parent_Email": "={{ $('Format Email Data').item.json.email }}",
            "Tip_Category": "={{ $('Format Email Data').item.json.tip_category }}"
          },
          "schema": [
            {
              "id": "Timestamp",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Parent_Email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Parent_Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Pet_Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Pet_Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Tip_Category",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Tip_Category",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Parent_Email"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1157171316,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1qd1H_IY_KEtB1C-ZJzpdmw9_yQEqdpnrf4ZdlV02gW4/edit#gid=1157171316",
          "cachedResultName": "Email_Log"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1qd1H_IY_KEtB1C-ZJzpdmw9_yQEqdpnrf4ZdlV02gW4",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1qd1H_IY_KEtB1C-ZJzpdmw9_yQEqdpnrf4ZdlV02gW4/edit?usp=drivesdk",
          "cachedResultName": "N8N SHEETS TEST"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "zyEOPkCfmHTXNm4V",
          "name": "Google Sheets (Dummy Account)"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "6a2afbfa-bc25-4776-921a-dd639b634c7a",
      "name": "检查状态",
      "type": "n8n-nodes-base.wait",
      "position": [
        2704,
        304
      ],
      "webhookId": "eabe5ece-2d48-4a23-b691-101e625ac828",
      "parameters": {
        "amount": 2
      },
      "typeVersion": 1.1
    },
    {
      "id": "011414fc-c326-4cd7-b5af-b00d986b1608",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -880,
        -64
      ],
      "parameters": {
        "width": 864,
        "height": 544,
        "content": "## 每周向宠物主人发送 AI 生成的、基于位置和年龄的健康提示。"
      },
      "typeVersion": 1
    },
    {
      "id": "92430d38-0a38-4b96-8a72-7517f16f5baa",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        384,
        272
      ],
      "parameters": {
        "color": 7,
        "width": 192,
        "height": 112,
        "content": "**加载所有状态为\"活跃\"的行**"
      },
      "typeVersion": 1
    },
    {
      "id": "59a432e6-2f31-4919-a7fd-908aeb2948ff",
      "name": "便签 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        624,
        256
      ],
      "parameters": {
        "color": 7,
        "width": 224,
        "height": 208,
        "content": "**跳过如果:**"
      },
      "typeVersion": 1
    },
    {
      "id": "0927faad-6699-41f3-9082-9133f85a9111",
      "name": "便签 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1024,
        224
      ],
      "parameters": {
        "color": 7,
        "width": 288,
        "height": 192,
        "content": "**将出生日期转换为可读年龄:**"
      },
      "typeVersion": 1
    },
    {
      "id": "daeda379-8395-4133-b7f5-cf4254129b27",
      "name": "便签 4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1360,
        224
      ],
      "parameters": {
        "color": 7,
        "width": 304,
        "height": 208,
        "content": "**基于以下内容的特定气候建议:**"
      },
      "typeVersion": 1
    },
    {
      "id": "628e8125-7d58-4841-89a1-7460bbb7cc2b",
      "name": "便签 5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2160,
        288
      ],
      "parameters": {
        "color": 7,
        "width": 304,
        "height": 192,
        "content": "更新:最后发送邮件日期 = 当前时间戳"
      },
      "typeVersion": 1
    },
    {
      "id": "136e8aa3-f5d8-4786-8e00-08d25bb7cef3",
      "name": "加载宠物信息",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        432,
        80
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "Active",
              "lookupColumn": "Status"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1625335217,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1qd1H_IY_KEtB1C-ZJzpdmw9_yQEqdpnrf4ZdlV02gW4/edit#gid=1625335217",
          "cachedResultName": "Parents_Children"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1qd1H_IY_KEtB1C-ZJzpdmw9_yQEqdpnrf4ZdlV02gW4",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1qd1H_IY_KEtB1C-ZJzpdmw9_yQEqdpnrf4ZdlV02gW4/edit?usp=drivesdk",
          "cachedResultName": "N8N SHEETS TEST"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "zyEOPkCfmHTXNm4V",
          "name": "Google Sheets (Dummy Account)"
        }
      },
      "typeVersion": 4.7
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "bfff3b2c-40b9-4522-a862-e99f353745c2",
  "connections": {
    "Load Pet Info": {
      "main": [
        [
          {
            "node": "Filter: Active + 7-Day Check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 2 Seconds": {
      "main": [
        [
          {
            "node": "Process Pets One-by-One",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Pet Age": {
      "main": [
        [
          {
            "node": "Generate Personalized Tip",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Email Data": {
      "main": [
        [
          {
            "node": "Send via SendGrid (Disabled)",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send Health Tip using Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log to Email_Log Sheet": {
      "main": [
        [
          {
            "node": "Wait 2 Seconds",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Pets One-by-One": {
      "main": [
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Calculate Pet Age",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Personalized Tip": {
      "main": [
        [
          {
            "node": "Format Email Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Health Tip using Gmail": {
      "main": [
        [
          {
            "node": "Update Last_Email_Sent Date",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Last_Email_Sent Date": {
      "main": [
        [
          {
            "node": "Log to Email_Log Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter: Active + 7-Day Check": {
      "main": [
        [
          {
            "node": "Process Pets One-by-One",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send via SendGrid (Disabled)": {
      "main": [
        [
          {
            "node": "Update Last_Email_Sent Date",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Weekly Trigger (Mondays 9am)": {
      "main": [
        [
          {
            "node": "Load Pet Info",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级

需要付费吗?

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

工作流信息
难度等级
高级
节点数量19
分类-
节点类型10
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Dahiana

Dahiana

@mssporto

No-Code Specialist with more than 10 years of experience in Digital Marketing. Currently working with Bubble. Webflow, AI, Agents and N8N.

外部链接
在 n8n.io 查看

分享此工作流