Read Email (IMAP)
从 IMAP 服务器读取邮件。
连接 IMAP 邮箱,按 IMAP 条件搜索一个文件夹,返回匹配邮件的主题、发件人、日期、原始文本正文和属性;无匹配时从 empty 输出。
工作原理
- 解析配置。
connection_id、box(默认INBOX)、searchCriteria(默认["UNSEEN"])和markSeen(默认 true)缺失时回退到输入 payload 中的同名键;空的box或空条件数组视为未设置。 - 解析凭据:
host、port(默认 993)和tls(默认 true)取自凭据配置;username(或user)和password(或pass)取自密钥。认证最多等待 10 秒。 - 打开
box,执行搜索,并获取每封匹配邮件的HEADER和TEXT部分。启用markSeen时,已获取的邮件会被标记为已读。 - 将每封邮件映射为
{ subject, from, date, body, attributes },然后关闭连接。 - 至少有一封邮件时以
{ emails }从out输出;没有邮件时以{}从empty输出。
在工作流中
节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。
{
"node_id": "node-read-invoices",
"label": "Read invoice mailbox",
"operator_slug": "io.imap",
"operator_version": "1.0.0",
"config": {
"connection_id": "pi-credential-xxxx",
"box": "INBOX",
"searchCriteria": [
"UNSEEN"
],
"markSeen": true
}
}{
"ok": true,
"data": {
"emails": [
{
"subject": "Invoice INV-2026-0042",
"from": "Billing <[email protected]>",
"date": "Wed, 25 Nov 2026 14:12:09 +0000",
"body": "Hello,\r\nPlease find the invoice attached.\r\n",
"attributes": {
"uid": 1842,
"flags": [
"\\Seen"
],
"date": "2026-11-25T14:12:09.000Z"
}
}
]
},
"port": "out"
}配置
-
connection_idstring 必填 -
IMAP 邮件服务器的凭据。接受 `basic-auth`(用户名 + 密码 + 主机 + 端口)类型的凭据。
-
boxstring 可选 -
searchCriteriaarray 可选 -
搜索条件,例如 UNSEEN、ALL 或 ['SINCE', date]
-
markSeenboolean 可选
代码中的行为
除 schema 描述之外,实现代码对这些键的实际处理。
-
searchCriteria - 以数组形式给出的 IMAP 搜索条件,例如
["UNSEEN"]、["ALL"]或["UNSEEN", ["SINCE", "2026-11-01"]]。空数组会回退到 payload,再回退到["UNSEEN"]。 -
markSeen - 只有显式设为
false才会保持邮件未读。在默认UNSEEN条件下,正是该设置使下一次运行不会返回相同的邮件。 -
connection_id - 接受
basic-auth凭据。包含:的值或 JSON 对象会被视为本地测试用的原始host:port,用户名和密码从输入 payload 读取。
输出端口
out 默认 搜索至少匹配一封邮件。subject、from 和 date 为各邮件头的第一个值;body 为原始 TEXT 部分(多部分邮件为 MIME 源码);attributes 包含 IMAP 的 uid、flags 和 date。
{
"emails": [
{
"subject": "Invoice INV-2026-0042",
"from": "Billing <[email protected]>",
"date": "Wed, 25 Nov 2026 14:12:09 +0000",
"body": "Hello,\r\nPlease find the invoice attached.\r\n",
"attributes": {
"uid": 1842,
"flags": [
"\\Seen"
],
"date": "2026-11-25T14:12:09.000Z"
}
}
]
}empty 搜索未匹配到任何邮件。
{}error 缺少 connection_id,或凭据、连接、登录、文件夹、搜索失败。数据为 { error, details },其中 details 包含错误的 code、stack 及其原始序列化内容。
{
"error": "Invalid credentials (Failure)",
"details": {
"code": null,
"stack": "<stack>",
"raw": "<serialized error>"
}
}在表达式中
后续节点可通过 $("Read Email (IMAP)").item.json.<路径> 读取此节点输出中的内容(请把 Read Email (IMAP) 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 out 返回的路径,依据“端口”一节所示的输出。
| 表达式 | Editor | Worker |
|---|---|---|
$("Read Email (IMAP)").item.json.emails找到的邮件列表 |
错误
| 消息 | 端口 | 原因与处理 |
|---|---|---|
connection_id is required (check config or config.payload) | error | 配置和输入 payload 中都没有凭据。请选择一个 IMAP 凭据。 |
<IMAP server error> | error | 用户名或密码错误、box 指定的文件夹不存在,或搜索条件无效。若邮件服务商要求使用应用专用密码,请将其保存在凭据中。 |
Failed to resolve connection <connection_id>: <detail> | error | 凭据不存在或此工作流无权使用。 |
输入契约
-
connection_idstring 必填 -
boxstring 可选 -
searchCriteriaarray 可选 -
markSeenboolean 可选
输出契约
-
emailsarray 可选 -
找到的邮件列表
契约(JSON Schema)
与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。
{
"slug": "io.imap",
"name": "Read Email (IMAP)",
"category": "io",
"version": "1.0.0",
"description": "Read emails from IMAP server.",
"capabilities": [
"email",
"imap",
"communication"
],
"config_schema": {
"type": "object",
"properties": {
"connection_id": {
"type": "string",
"title": "IMAP Credential",
"description": "Credential for the IMAP mail server. Accepts credentials of type `basic-auth` (username + password + host + port).",
"ui_widget": "connection_picker",
"ui_options": {
"credential_types": [
"basic-auth"
],
"types": [
"imap"
]
}
},
"box": {
"type": "string",
"default": "INBOX"
},
"searchCriteria": {
"type": "array",
"default": [
"UNSEEN"
],
"description": "Criteria like UNSEEN, ALL, or ['SINCE', date]"
},
"markSeen": {
"type": "boolean",
"default": true
}
},
"required": [
"connection_id"
]
},
"input_contract_schema": {
"type": "object",
"properties": {
"connection_id": {
"type": "string"
},
"box": {
"type": "string"
},
"searchCriteria": {
"type": "array"
},
"markSeen": {
"type": "boolean"
}
},
"required": [
"connection_id"
]
},
"output_contract_schema": {
"type": "object",
"properties": {
"emails": {
"type": "array",
"description": "List of found emails"
}
}
},
"ports": [
{
"port_id": "out",
"label": "Emails",
"description": "List of found emails",
"is_default": true,
"supports_condition": true
},
{
"port_id": "empty",
"label": "No Emails",
"description": "No emails found matching criteria",
"is_default": false,
"supports_condition": true
},
{
"port_id": "error",
"label": "Error",
"description": "Connection or fetch error",
"is_default": false,
"supports_condition": false
}
],
"execution_mode": "async",
"required_resources": [],
"compatible_worker_pools": [
"standard-io"
],
"tags": [
"email",
"communication"
],
"is_stateful": false,
"publisher": {
"identity": "org_link_loom",
"profile": {
"name": "Link Loom",
"verified": true,
"url": "https://me.veripass.com/link-loom",
"logo_url": null
}
}
}{
"type": "object",
"properties": {
"connection_id": {
"type": "string",
"title": "IMAP Credential",
"description": "Credential for the IMAP mail server. Accepts credentials of type `basic-auth` (username + password + host + port).",
"ui_widget": "connection_picker",
"ui_options": {
"credential_types": [
"basic-auth"
],
"types": [
"imap"
]
}
},
"box": {
"type": "string",
"default": "INBOX"
},
"searchCriteria": {
"type": "array",
"default": [
"UNSEEN"
],
"description": "Criteria like UNSEEN, ALL, or ['SINCE', date]"
},
"markSeen": {
"type": "boolean",
"default": true
}
},
"required": [
"connection_id"
]
}{
"type": "object",
"properties": {
"connection_id": {
"type": "string"
},
"box": {
"type": "string"
},
"searchCriteria": {
"type": "array"
},
"markSeen": {
"type": "boolean"
}
},
"required": [
"connection_id"
]
}{
"type": "object",
"properties": {
"emails": {
"type": "array",
"description": "List of found emails"
}
}
}[
{
"port_id": "out",
"label": "Emails",
"description": "List of found emails",
"is_default": true,
"supports_condition": true
},
{
"port_id": "empty",
"label": "No Emails",
"description": "No emails found matching criteria",
"is_default": false,
"supports_condition": true
},
{
"port_id": "error",
"label": "Error",
"description": "Connection or fetch error",
"is_default": false,
"supports_condition": false
}
]执行
- 执行方式
async- 有状态
- 否
- 凭据
- 在服务器端根据
connection_id解析,密钥不会进入工作流。 - 能力
emailimapcommunication- 标签
emailcommunication
说明与限制
- 一次运行会获取所有匹配邮件,没有数量限制或分页;在大型邮箱中请收窄
searchCriteria。 - 不会提取附件,附件保留在原始 MIME
body中。 markSeen: true时不具备幂等性:每次运行都会改变邮箱状态。
已对照编排器代码核实 · 31e874b · 2026-11-26