跳到主要内容

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

  1. Sign in to your Google Account at accounts.google.com
  2. Click "Security" in the left navigation menu
  3. Find "Signing in to Google" section
  4. Click "2-Step Verification"
  5. 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

  1. Return to Security page after enabling 2-Step Verification
  2. Click "App passwords" (under "Signing in to Google")
  3. Select "Mail" as the app type
  4. Select "Other" as the device type
  5. Enter a name like "OV80i Node-RED Email"
  6. Click "Generate"

1.3 Save Your App Password

  1. Copy the 16-character password that Google displays
  2. Store it securely - you'll need it for Node-RED configuration
  3. 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

  1. Open Node-RED on your OV80i camera
  2. Look in the left palette for an "email" node in the output section
  3. If missing, you'll need to install the email package

2.2 Install Email Package (If Required)

  1. Click the hamburger menu (≡) in Node-RED
  2. Select "Manage palette"
  3. Click "Install" tab
  4. Search for "node-red-node-email"
  5. Click "Install" next to the package

Step 3: Create Basic Email Flow

3.1 Add Required Nodes

  1. Navigate to IO Block to access Node-RED
  2. Drag these nodes from the palette to your canvas:
    • Inject node (for testing)
    • Email node (from output section)
  3. Connect inject output to email input

3.2 Basic Flow Structure

Inject → Email

Flow purpose: Simple email sending for testing and basic notifications.

image.png

Step 4: Configure Email Content

4.1 Set Up Inject Node

  1. Double-click the inject node to open properties
  2. Set the payload:
    • Payload type: "string"
    • Payload value: Your email body text (e.g., "Inspection alert from OV80i")
  3. Add email subject:
    • Click "+ add" to add a property

    • Property name: "topic"

    • Property value: Your email subject (e.g., "OV80i 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):

OV80i Inspection Alert - Station 1

4.3 Save Inject Configuration

  1. Give the node a name like "Email Trigger"
  2. Click "Done" to save the configuration

Step 5: Configure Email SMTP Settings

5.1 Set Up Email Node

  1. Double-click the email node to open properties
  2. Configure basic settings:
    • Name: "Send Alert Email" (or descriptive name)
    • To: Recipient email address (e.g., 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: Your full Gmail address (e.g., alerts@company.com)
  6. Password: The 16-character app password from Step 1

5.3 Security Settings

  1. Check "Check server certificate is valid"
  2. Verify all settings are entered correctly
  3. Click "Done" to save email node configuration

Checkpoint: Your email node should show no error indicators and display the recipient address.

image.png

Step 6: Test Your Email Flow

6.1 Deploy and Test

  1. Click "Deploy" button in the top-right corner
  2. Wait for "Successfully deployed" message
  3. Click the inject node button (gray square on the left side)

6.2 Verify Email Delivery

  1. Check the recipient email for the test message
  2. Check spam folder if email doesn't appear in inbox
  3. 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:

  1. Find your main inspection flow (starts with "All Block Outputs")
  2. Add your email flow as a branch from inspection processing
  3. 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

image.png

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 根据需要进行自定义

  1. 更新贵组织的电子邮件地址
  2. 根据具体需求修改电子邮件内容
  3. 调整触发时机和触发条件
  4. 在生产部署前进行充分测试

故障排除

常见问题

问题症状解决方案
身份验证失败"登录失败" 错误验证应用程序密码是否正确且已启用两步验证
连接超时未发送邮件,出现超时错误检查防火墙设置,验证 SMTP 服务器和端口
邮件被标记为垃圾邮件邮件已送达但在垃圾邮件文件夹中将发件人添加到安全名单,改进邮件内容
流程未触发无调试输出检查流程连接和触发条件

调试您的电子邮件流

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

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

您的 OV80i 摄像头现在可以:

发送检测结果的自动化电子邮件通知

提供带有检查详情的富文本信息

支持多收件人和升级工作流程

提供定期报告和摘要

基于检查结果处理条件消息

最佳实践

邮件管理

  • 使用描述性主题,带有清晰的状态指示
  • 保持信息简洁但信息量充足
  • 包含时间戳和工位标识符
  • 在通知中提供可操作的信息

安全性与可靠性

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

性能考虑

  • 限制电子邮件发送频率 以避免垃圾邮件过滤
  • 为不同类型的警报使用合适的分发列表
  • 对高容量系统实施速率限制
  • 在包含大型附件时,考虑邮件大小

后续步骤

在设置好电子邮件通知后:

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

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

🔗 相关参考