AI 驱动文档
您想了解什么?
通过 Node-RED 发送电子邮件
本教程演示如何使用 Node-RED 针对 OV80i 摄像头设置自动化电子邮件通知。您将学习如何配置 Gmail 集成,并创建将检测警报、系统状态更新以及故障通知直接发送到您的电子邮件的流程。
将要构建的内容: 使用 Gmail SMTP,将 OV80i 的检测结果、警报和通知发送给指定收件人。
实际应用场景: 当检测失败时立即通过电子邮件收到警报,将每日质量报告发送给管理层,或在系统出现问题时通知维护团队——这一切均可由您的视觉检测系统自动完成。
先决条件
- 拥有 Node-RED 访问权限的 OV80i 摄像头
- 用于发送电子邮件的 Gmail 帐户
- 对 Node-RED 流程有基础理解
- 能访问 Google 帐户的安全设置
教程概览
将要构建的内容: 一个 Node-RED 流,能够自动发送带有检测结果和系统警报的电子邮件通知。
所需时间: 20-30 分钟(含 Gmail 设置)
掌握的技能: 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
2-Step Verification is required before you can create app passwords.
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 "OV80i 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 OV80i 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:
- Inject node (for testing)
- Email node (from output section)
- Connect inject output to email input
3.2 Basic Flow Structure
Inject → Email
Flow purpose: Simple email sending for testing and basic notifications.

Step 4: Configure Email Content
4.1 Set Up Inject Node
- Double-click the inject node to open properties
- Set the payload:
- Payload type: "string"
- Payload value: Your email body text (e.g., "Inspection alert from OV80i")
- Add email subject:
-
Click "+ add" to add a property
-
Property name: "topic"
-
Property value: Your email subject (e.g., "OV80i 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):
OV80i Inspection Alert - Station 1
4.3 Save Inject Configuration
- Give the node a name like "Email Trigger"
- Click "Done" to save the configuration
Step 5: Configure Email SMTP Settings
5.1 Set Up Email Node
- Double-click the email node to open properties
- Configure basic settings:
- Name: "Send Alert Email" (or descriptive name)
- To: Recipient email address (e.g., quality@company.com)
5.2 Configure Gmail SMTP
- Server:
smtp.gmail.com - Port:
465 - Check "Use secure connection"
- Auth type:
Basic - Userid: Your full Gmail address (e.g., alerts@company.com)
- Password: The 16-character app password from Step 1
5.3 Security Settings
- Check "Check server certificate is valid"
- Verify all settings are entered correctly
- Click "Done" to save email node configuration
Checkpoint: Your email node should show no error indicators and display the recipient address.

Step 6: Test Your Email Flow
6.1 Deploy and Test
- Click "Deploy" button in the top-right corner
- Wait for "Successfully deployed" message
- Click the inject node button (gray square on the left side)
6.2 Verify Email Delivery
- Check the recipient email for the test message
- Check spam folder if email doesn't appear in inbox
- Look for any error messages in Node-RED debug panel
6.3 Troubleshoot If Needed
Common issues:
- Wrong app password: Regenerate Gmail app password
- SMTP settings: Verify server and port are correct
- Firewall: Ensure outbound SMTP traffic is allowed
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 as a branch from inspection processing
- Connect after inspection logic but parallel to final results
7.2 Example Integration Flow
All Block Outputs → [Inspection Logic] → Final Pass/Fail
↓
Format Email → Send Email

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