AI 驱动文档
您想了解什么?
通过 Node-RED 发送邮件
本教程演示如何使用 Node-RED 从 OV10i 摄像头设置自动化邮件通知。您将学习配置 Gmail 集成,并创建将检验警报、系统状态更新以及故障通知直接发送到您的邮箱的工作流。
What You'll Build: 将使用 Gmail SMTP 的一个自动邮件系统,向指定收件人发送 OV10i 检测结果、警报和通知。
Real-World Application: 当检测失败时立即收到邮件警报;向管理层发送每日质量报告;或在系统出现问题时通知维护团队——以上均可从您的视觉检测系统自动完成。
Prerequisites
- OV10i 摄像头,具备 Node-RED 访问权限
- 用于发送邮件的 Gmail 帐户
- 对 Node-RED 流的基本理解
- 访问 Google 帐户安全设置
Tutorial Overview
What we'll build: 一个 Node-RED 流,能够自动发送带有检测结果和系统警报的邮件通知。
Time required: 20-30 分钟(包括 Gmail 设置)
Skills learned: Gmail 应用密码设置、SMTP 配置、自动邮件通知
Step 1: Set Up Gmail App Password
1.1 Enable 2-Step Verification
- Sign in to your Google Account at accounts.google.com
- Click "Security" in the left navigation menu
- Find "Signing in to Google" section
- Click "2-Step Verification"
- Follow the prompts to enable 2-Step Verification if not already enabled
两步验证是在您能够创建应用密码之前所必需的。
1.2 Generate App Password
- Return to Security page after enabling 2-Step Verification
- Click "App passwords" (under "Signing in to Google")
- Select "Mail" as the app type
- Select "Other" as the device type
- Enter a name like "OV10i Node-RED Email"
- Click "Generate"
1.3 Save Your App Password
- Copy the 16-character password that Google displays
- Store it securely - you'll need it for Node-RED configuration
- Note: This password is only shown once. If lost, generate a new one
Checkpoint: You should have a 16-character Gmail app password saved for Node-RED use.
Step 2: Install Email Nodes (If Needed)
2.1 Check for Email Nodes
- Open Node-RED on your OV10i camera
- Look in the left palette for an "email" node in the output section
- If missing, you'll need to install the email package
2.2 Install Email Package (If Required)
- Click the hamburger menu (≡) in Node-RED
- Select "Manage palette"
- Click "Install" tab
- Search for "node-red-node-email"
- Click "Install" next to the package
Step 3: Create Basic Email Flow
3.1 Add Required Nodes
- Navigate to IO Block to access Node-RED
- Drag these nodes from the palette to your canvas:
- 注入节点(用于测试)
- Email 节点(来自输出区)
- Connect inject output to email input
3.2 基本流程结构
Inject → Email
流程目的:用于测试和基本通知的简易邮件发送。

第4步:配置邮件内容
4.1 设置注入节点
- 双击注入节点 以打开属性
- 设置有效载荷:
- 有效载荷类型: "string"
- 有效载荷值:您的邮件正文文本(例如“来自 OV10i 的检查警报”)
- 添加邮件主题:
-
点击“+ add” 以添加属性
-
属性名称: "topic"
-
属性值: 您的邮件主题(例如“OV10i 检查警报”)

-
4.2 示例基本配置
有效载荷(邮件正文):
Inspection completed at Station 1
Status: Alert triggered
Time: Check timestamp for details
主题(邮件主题):
OV20i Inspection Alert - Station 1
4.3 保存注入节点配置
- 为节点命名,如 "邮件触发器"
- 点击“完成” 以保存配置
第5步:配置邮件 SMTP 设置
5.1 设置邮件节点
- 双击邮件节点 以打开属性
- 配置基本设置:
- 名称: "发送警报邮件"(或描述性名称)
- 收件人:接收者邮箱地址(例如 quality@company.com)
5.2 配置 Gmail SMTP
- 服务器:
smtp.gmail.com - 端口:
465 - 勾选 "使用安全连接"
- 认证类型:
Basic - 用户名:完整的 Gmail 地址(例如 alerts@company.com)
- 密码:来自步骤1的 16 位应用程序密码
5.3 安全设置
- 勾选 "检查服务器证书是否有效"
- 请正确输入所有设置
- 点击“完成” 以保存邮件节点配置
检查点: 邮件节点不应显示错误指示并显示收件人地址。

第6步:测试您的邮件流
6.1 部署并测试
- 点击右上角的“部署”按钮
- 等待“部署成功”消息
- 点击注入节点按钮(左侧的灰色方形)
6.2 验证邮件送达
- 检查测试邮件的收件人邮箱
- 若邮件未出现在收件箱,请检查垃圾邮件文件夹
- 在 Node-RED 调试面板中查看任何错误信息
6.3 如有需要,故障排除
常见问题:
- 错误的应用程序密码:请重新生成 Gmail 应用程序密码
- SMTP 设置:请验证服务器和端口是否正确
- 防火墙:确保允许出站 SMTP 流量
第7步:与检验结果的集成
7.1 连接到检验流程
根据检验结果发送邮件:
- 找到您的主检验流程(以“All Block Outputs”开头)
- 将您的邮件流程作为检验处理的一个分支添加
- 在检验逻辑之后连接,但与最终结果并行
7.2 示例集成流程
All Block Outputs → [Inspection Logic] → Final Pass/Fail
↓
Format Email → Send Email

7.3 动态邮件内容
Replace the inject node with a function node for dynamic content:
将 inject 节点替换为用于动态内容的 function 节点:
// 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 导入现成的流程
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 根据您的需求进行自定义
- 更新贵组织的电子邮件地址
- 修改邮件内容 以符合您的具体需求
- 调整时序和触发条件
- 在生产部署前进行充分测试
故障排除
常见问题
| 问题 | 症状 | 解决方法 |
|---|---|---|
| 身份验证失败 | ""Login failed" 错误 | 验证应用密码是否正确且已启用两步验证 |
| 连接超时 | 未发送电子邮件,出现超时错误 | 检查防火墙设置,验证 SMTP 服务器和端口 |
| 邮件被标记为垃圾邮件 | 邮件已送达但在垃圾邮件文件夹 | 将发件人添加到安全名单,优化邮件内容 |
| 流未触发 | 无调试输出 | 检查流程连接和触发条件 |
调试您的邮件流程
- 在每个步骤之后添加调试节点 以跟踪数据
- 检查 Node-RED 日志 以获取详细错误信息
- 如有需要,请使用外部电子邮件客户端测试 SMTP 设置
- 验证从相机到 Gmail 服务器的网络连通性
成功!您的邮件集成已完成
现在,您的 OV10i 摄像头可以:
✅ 发送针对检查结果的自动化邮件通知
✅ 发送包含检查详情的丰富、格式化的消息
✅ 支持多收件人及升级工作流
✅ 提供定期报告和摘要
✅ 根据检查结果进行条件消息处理
最佳实践
邮件管理
- 使用描述性主题,附带明确的状态指示
- 保持消息简明扼要,同时信息量充足
- 包含时间戳和站点标识符
- 在通知中提供可执行信息
安全性与可靠性
- 保护应用密码,安全存储并定期轮换
- 为系统通知使用专用邮箱账户
- 定期测试邮件投递 以确保可靠性
- 监控投递失败情况,并提供备用通知方式
性能注意事项
- 限制电子邮件发送频率,以避免触发垃圾邮件检测
- 为不同的告警类型使用合适的收件人列表
- 对高吞吐量系统实施限流
- 在包含大附件时,请考虑邮件大小
下一步
设置完电子邮件通知后:
- 为不同类型的告警创建电子邮件模板
- 为不同的利益相关者设置分发列表
- 为关键问题实现升级工作流
- 为管理层创建定期报告
- 与其他通知系统集成(SMS、Microsoft Teams 等)
The Integration Builder 可以从纯英文描述生成完整的电子邮件通知流程。请描述您想要的内容(例如“在发现缺陷时发送包含检测图像的电子邮件”),即可在几秒钟内获得一个就绪生产的 Node-RED 流。