跳到主要内容

AI 驱动文档

您想了解什么?

使用 Node-RED 发送邮件

本教程向您展示如何使用 Node-RED 从 OV20i 摄像头设置自动邮件通知。您将学习配置 Gmail 集成,并创建将检测警报、系统状态更新,以及故障通知直接发送到邮箱的工作流。

您将构建的内容: 一个使用 Gmail SMTP 自动发送 OV20i 检查结果、警报和通知的邮件系统。

实际应用场景: 当检查失败时立即收到邮件通知,向管理层发送每日质量报告,或通知维护团队系统问题——全部由您的视觉检查系统自动完成。

先决条件

  • OV20i 摄像头(具备 Node-RED 访问权限)
  • 用于发送邮件的 Gmail 帐户
  • 对 Node-RED 流程的基本了解
  • 能访问 Google 账户安全设置

Tutorial Overview

我们将构建的内容: 一个 Node-RED 流自动发送带有检测结果和系统警报的邮件通知。

所需时间: 20-30 分钟(含 Gmail 设置)

所学技能: Gmail 应用密码设置、SMTP 配置、自动邮件通知

第 1 步:设置 Gmail 应用密码

1.1 启用两步验证

  1. 在 Google 账户登录页面 accounts.google.com
  2. 在左侧导航菜单中点击“Security”(安全)
  3. 找到“Signing in to Google” 部分
  4. 点击“2-Step Verification”(两步验证)
  5. 按照提示启用两步验证(若尚未启用)
备注

在您可以创建应用密码之前,需要启用两步验证。

1.2 生成应用密码

  1. 在启用两步验证后返回 Security 页
  2. 点击“App passwords”(在“Signing in to Google” 下)
  3. 将应用类型选择为“Mail”
  4. 将设备类型选择为“Other”
  5. 输入一个名称,如“OV20i Node-RED Email”
  6. 点击“Generate”

1.3 保存您的应用密码

  1. 复制 Google 显示的 16 位密码
  2. 将其安全保存——您将需要它来进行 Node-RED 配置
  3. 注:此密码仅显示一次。如遗失,请生成一个新的

检查点: 您应已为 Node-RED 保存了一个 16 位 Gmail 应用密码。

第 2 步:安装邮箱节点(如有需要)

2.1 检查邮箱节点

  1. 在 OV20i 摄像头上打开 Node-RED
  2. 在左侧调色板的输出区查找“email”节点
  3. 如果缺失,您需要安装 email 包

2.2 安装邮箱包(如有需要)

  1. 在 Node-RED 中点击汉堡菜单(≡)
  2. 选择“Manage palette”
  3. 点击“Install”标签
  4. 搜索“node-red-node-email”
  5. 在该包旁边点击“Install”

第 3 步:创建基础邮件流

3.1 添加所需节点

  1. 导航至 IO Block 以访问 Node-RED
  2. 从调色板拖动以下节点到画布:
    • Inject node(用于测试)
    • Email node(来自输出区)
  3. 将 Inject 的输出连接到 Email 的输入

3.2 基本流结构

Inject → Email

Flow 目标: 用于测试和基本通知的简单邮件发送。

image.png

Step 4: Configure Email Content

4.1 Set Up Inject Node

  1. Double-click the inject node 以打开属性
  2. Set the payload:
    • Payload type: "string"
    • Payload value: 您的邮件正文文本(例如 "Inspection alert from OV20i")
  3. Add email subject:
    • Click "+ add" 以添加属性

    • Property name: "topic"

    • Property value: 您的邮件主题(例如 "OV20i Inspection Alert")

      image.png

4.2 Example Basic Configuration

Payload (email body):

Inspection completed at Station 1
Status: Alert triggered
Time: Check timestamp for details

Topic (email subject):

OV20i Inspection Alert - Station 1

4.3 Save Inject Configuration

  1. 为该节点命名 如 "Email Trigger"
  2. Click "Done" 保存配置

Step 5: Configure Email SMTP Settings

5.1 Set Up Email Node

  1. Double-click the email node 以打开属性
  2. Configure basic settings:
    • Name: "Send Alert Email"(或描述性名称)
    • To: 收件邮箱地址(例如 quality@company.com

5.2 Configure Gmail SMTP

  1. Server: smtp.gmail.com
  2. Port: 465
  3. Check "Use secure connection"
  4. Auth type: Basic
  5. Userid: 您的完整 Gmail 地址(例如 alerts@company.com
  6. Password: 来自 Step 1 的 16 位应用程序密码

5.3 Security Settings

  1. Check "Check server certificate is valid"
  2. Verify all settings 已正确输入
  3. Click "Done" 保存 email node 配置

Checkpoint: 您的 email node 应无错误指示并显示收件人地址。

image.png

Step 6: Test Your Email Flow

6.1 Deploy and Test

  1. Click "Deploy" 按钮位于右上角
  2. Wait for "Successfully deployed" 消息
  3. Click the inject node button(左侧的灰色方块)

6.2 Verify Email Delivery

  1. Check the recipient email 用于测试的邮件地址
  2. Check spam folder 若邮件未出现在收件箱中
  3. Look for any error messages 在 Node-RED 调试面板中查找错误信息

6.3 Troubleshoot If Needed

Common issues:

  • Wrong app password: 重新生成 Gmail 应用密码
  • SMTP settings: 验证服务器和端口是否正确
  • Firewall: 确保出站 SMTP 流量被允许

Step 7: Integration with Inspection Results

7.1 Connect to Inspection Flow

To send emails based on inspection results:

  1. Find your main inspection flow (starts with "All Block Outputs")
  2. Add your email flow 作为 inspection processing 的分支
  3. Connect after inspection logic 但与最终结果并行

7.2 Example Integration Flow

All Block Outputs → [Inspection Logic] → Final Pass/Fail

Format Email → Send Email

image.png

7.3 动态邮件内容

Replace the inject node with a function node for dynamic content:

// Dynamic email based on inspection results
const result = msg.payload.result ? "PASSED" : "FAILED";
const timestamp = new Date().toLocaleString();
const station = global.get("station_name") || "Unknown Station";

// Set email subject
msg.topic = `Inspection ${result} - ${station}`;

// Set email body
msg.payload = `Inspection Report:
Status: ${result}
Station: ${station}
Time: ${timestamp}
Image: ${msg.payload.image_url || "No image available"}

Please review and take appropriate action.`;

return msg;

Step 8: Complete Flow Example

8.1 Import Ready-Made Flow

You can import this complete flow JSON:

[
{
"id": "email_node_1",
"type": "e-mail",
"name": "Send Inspection Alert",
"server": "smtp.gmail.com",
"port": "465",
"secure": true,
"authtype": "BASIC",
"to": "quality@company.com"
},
{
"id": "format_email",
"type": "function",
"name": "Format Email Content",
"func": "const result = msg.payload.result ? 'PASSED' : 'FAILED';\nmsg.topic = `Inspection ${result}`;\nmsg.payload = `Status: ${result}\\nTime: ${new Date()}`;\nreturn msg;"
}
]

8.2 Customize for Your Needs

  1. Update email addresses for your organization
  2. Modify email content for your specific requirements
  3. Adjust timing and trigger conditions
  4. Test thoroughly before production deployment

故障排除

常见问题

问题症状解决方法
Authentication failed"Login failed" errors验证应用程序密码是否正确,并启用两步验证
Connection timeoutNo email sent, timeout errors检查防火墙设置,验证 SMTP 服务器及端口
Emails in spamEmails delivered but in spam folder将发件人添加到安全名单,改进邮件内容
Flow not triggeringNo debug output检查流程连接和触发条件

调试您的邮件流

  1. 在每个步骤之后添加调试节点以跟踪数据
  2. 检查 Node-RED 日志以获取详细错误信息
  3. 如有需要,使用外部邮件客户端测试 SMTP 设置
  4. 验证相机到 Gmail 服务器的网络连通性

成功!您的邮件集成已完成

您的 OV20i 摄像头现在可以:

发送自动化邮件通知用于检查结果

发送丰富、格式化的消息,包含检查详情

支持多个收件人及升级工作流

提供计划的报告及摘要

根据检查结果处理有条件的消息

最佳实践

电子邮件管理

  • 使用带有清晰状态指示的描述性主题
  • 保持消息简洁且信息充分
  • 包含时间戳和站点标识符
  • 在通知中提供可执行信息

安全性与可靠性

  • 保护应用密码 - 安全存储并定期轮换
  • 为系统通知使用专用的邮箱账户
  • 定期测试邮件投递以确保可靠性
  • 监控投递失败并具备备用通知方法

性能考量

  • 限制邮件发送频率,以避免触发垃圾邮件检测
  • 为不同警报类型使用合适的收件人名单
  • 对高并发系统实现速率限制
  • 在包含大附件时考虑邮件大小

后续步骤

设置好电子邮件通知后:

  1. 为不同类型的警报创建电子邮件模板
  2. 为不同利益相关者设置分发列表
  3. 为关键问题实现升级工作流
  4. 为管理层创建定期报表
  5. 与其他通知系统集成(SMS、Teams 等)
跳过手动设置

The Integration Builder 可以从一个简单的英文描述生成完整的电子邮件通知流程。请描述您想要的内容(例如“在发现缺陷时发送带有检验图像的电子邮件”),即可在几秒钟内获得可投入生产的 Node-RED 流。

🔗 相关链接