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 启用两步验证
- 在 Google 账户登录页面 accounts.google.com
- 在左侧导航菜单中点击“Security”(安全)
- 找到“Signing in to Google” 部分
- 点击“2-Step Verification”(两步验证)
- 按照提示启用两步验证(若尚未启用)
在您可以创建应用密码之前,需要启用两步验证。
1.2 生成应用密码
- 在启用两步验证后返回 Security 页面
- 点击“App passwords”(在“Signing in to Google” 下)
- 将应用类型选择为“Mail”
- 将设备类型选择为“Other”
- 输入一个名称,如“OV20i Node-RED Email”
- 点击“Generate”
1.3 保存您的应用密码
- 复制 Google 显示的 16 位密码
- 将其安全保存——您将需要它来进行 Node-RED 配置
- 注:此密码仅显示一次。如遗失,请生成一个新的
检查点: 您应已为 Node-RED 保存了一个 16 位 Gmail 应用密码。
第 2 步:安装邮箱节点(如有需要)
2.1 检查邮箱节点
- 在 OV20i 摄像头上打开 Node-RED
- 在左侧调色板的输出区查找“email”节点
- 如果缺失,您需要安装 email 包
2.2 安装邮箱包(如有需要)
- 在 Node-RED 中点击汉堡菜单(≡)
- 选择“Manage palette”
- 点击“Install”标签
- 搜索“node-red-node-email”
- 在该包旁边点击“Install”
第 3 步:创建基础邮件流
3.1 添加所需节点
- 导航至 IO Block 以访问 Node-RED
- 从调色板拖动以下节点到画布:
- Inject node(用于测试)
- Email node(来自输出区)
- 将 Inject 的输出连接到 Email 的输入
3.2 基本流结构
Inject → Email
Flow 目标: 用于测试和基本通知的简单邮件发送。

Step 4: Configure Email Content
4.1 Set Up Inject Node
- Double-click the inject node 以打开属性
- Set the payload:
- Payload type: "string"
- Payload value: 您的邮件正文文本(例如 "Inspection alert from OV20i")
- Add email subject:
-
Click "+ add" 以添加属性
-
Property name: "topic"
-
Property value: 您的邮件主题(例如 "OV20i Inspection Alert")

-
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
- 为该节点命名 如 "Email Trigger"
- Click "Done" 保存配置
Step 5: Configure Email SMTP Settings
5.1 Set Up Email Node
- Double-click the email node 以打开属性
- Configure basic settings:
- Name: "Send Alert Email"(或描述性名称)
- To: 收件邮箱地址(例如 quality@company.com)
5.2 Configure Gmail SMTP
- Server:
smtp.gmail.com - Port:
465 - Check "Use secure connection"
- Auth type:
Basic - Userid: 您的完整 Gmail 地址(例如 alerts@company.com)
- Password: 来自 Step 1 的 16 位应用程序密码
5.3 Security Settings
- Check "Check server certificate is valid"
- Verify all settings 已正确输入
- Click "Done" 保存 email node 配置
Checkpoint: 您的 email node 应无错误指示并显示收件人地址。

Step 6: Test Your Email Flow
6.1 Deploy and Test
- Click "Deploy" 按钮位于右上角
- Wait for "Successfully deployed" 消息
- Click the inject node button(左侧的灰色方块)
6.2 Verify Email Delivery
- Check the recipient email 用于测试的邮件地址
- Check spam folder 若邮件未出现在收件箱中
- 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:
- Find your main inspection flow (starts with "All Block Outputs")
- Add your email flow 作为 inspection processing 的分支
- Connect after inspection logic 但与最终结果并行
7.2 Example Integration Flow
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:
// 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
- Update email addresses for your organization
- Modify email content for your specific requirements
- Adjust timing and trigger conditions
- Test thoroughly before production deployment
故障排除
常见问题
| 问题 | 症状 | 解决方法 |
|---|---|---|
| Authentication failed | "Login failed" errors | 验证应用程序密码是否正确,并启用两步验证 |
| Connection timeout | No email sent, timeout errors | 检查防火墙设置,验证 SMTP 服务器及端口 |
| Emails in spam | Emails delivered but in spam folder | 将发件人添加到安全名单,改进邮件内容 |
| Flow not triggering | No debug output | 检查流程连接和触发条件 |
调试您的邮件流
- 在每个步骤之后添加调试节点以跟踪数据
- 检查 Node-RED 日志以获取详细错误信息
- 如有需要,使用外部邮件客户端测试 SMTP 设置
- 验证相机到 Gmail 服务器的网络连通性
成功!您的邮件集成已完成
您的 OV20i 摄像头现在可以:
✅ 发送自动化邮件通知用于检查结果
✅ 发送丰富、格式化的消息,包含检查详情
✅ 支持多个收件人及升级工作流
✅ 提供计划的报告及摘要
✅ 根据检查结果处理有条件的消息
最佳实践
电子邮件管理
- 使用带有清晰状态指示的描述性主题
- 保持消息简洁且信息充分
- 包含时间戳和站点标识符
- 在通知中提供可执行信息
安全性与可靠性
- 保护应用密码 - 安全存储并定期轮换
- 为系统通知使用专用的邮箱账户
- 定期测试邮件投递以确保可靠性
- 监控投递失败并具备备用通知方法
性能考量
- 限制邮件发送频率,以避免触发垃圾邮件检测
- 为不同警报类型使用合适的收件人名单
- 对高并发系统实现速率限制
- 在包含大附件时考虑邮件大小
后续步骤
设置好电子邮件通知后:
- 为不同类型的警报创建电子邮件模板
- 为不同利益相关者设置分发列表
- 为关键问题实现升级工作流
- 为管理层创建定期报表
- 与其他通知系统集成(SMS、Teams 等)
The Integration Builder 可以从一个简单的英文描述生成完整的电子邮件通知流程。请描述您想要的内容(例如“在发现缺陷时发送带有检验图像的电子邮件”),即可在几秒钟内获得可投入生产的 Node-RED 流。