本页内容
Sommatic 文档
打开控制台

Send Email (SMTP)

通过 SMTP 服务器发送邮件。

以 Markdown 查看
在以下应用中打开
输入与输出 可用 io.smtp 版本 1.0.0 执行方式: async

通过凭据描述的 SMTP 服务器发送一封邮件,并返回中继服务器的投递报告。

工作原理

  1. 解析配置。connection_id、to、subject、text 和 html 缺失时回退到输入 payload 中的同名键;connection_id、to 和 subject 为必填。
  2. 解析凭据:host、port(默认 587)、secure(默认 false)和 from 取自凭据配置;username(或 user)和 password(或 pass)取自密钥。from 默认为用户名。
  3. 打开 SMTP 传输,仅在存在用户名时进行认证。
  4. 使用 from、to、subject、text 和 html 发送邮件,并以 { result } 从 out 返回中继报告。

在工作流中

节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。

{
  "node_id": "node-send-alert",
  "label": "Send alert email",
  "operator_slug": "io.smtp",
  "operator_version": "1.0.0",
  "config": {
    "connection_id": "pi-credential-xxxx",
    "to": "ops@example.com",
    "subject": "Order {{ $json.order_id }} requires review",
    "text": "Order {{ $json.order_id }} exceeded the approval limit.",
    "html": "<p>Order <strong>{{ $json.order_id }}</strong> exceeded the approval limit.</p>"
  }
}

配置

connection_id string 必填

SMTP 服务器的凭据。接受 `basic-auth`(用户名 + 密码 + 主机 + 端口)或 `connection-string`(smtp:// / smtps:// URI)类型的凭据。

to string 必填

收件人邮箱(可多个)

subject string 必填
text string 可选

纯文本正文

html string 可选

HTML 正文

代码中的行为

除 schema 描述之外,实现代码对这些键的实际处理。

connection_id
请使用在配置中包含 host、port、secure 和 from 的 basic-auth 凭据。来自已保存凭据的 connection-string 密钥不会被解析。以 { 开头或包含 ://、@ 的值会被就地解析(JSON 对象或 smtp://user:pass@host:port URI),仅用于本地测试。
html
两者都设置时与 text 一同发送;邮件客户端会显示 HTML 部分。

输出端口

out 默认

中继已接受邮件。result 为邮件库的发送报告:accepted、rejected、envelope、messageId、response,以及耗时字段。

数据
{
  "result": {
    "accepted": [
      "ops@example.com"
    ],
    "rejected": [],
    "envelope": {
      "from": "no-reply@example.com",
      "to": [
        "ops@example.com"
      ]
    },
    "messageId": "<5f1c2a7e-8b1d-4a3e-9c0f-2d6e7b8a9c10@example.com>",
    "response": "250 2.0.0 OK queued"
  }
}
error

缺少必填字段、无法解析凭据,或连接、登录、发送失败。

数据
{
  "error": "Invalid login: 535 5.7.8 Authentication credentials invalid"
}

在表达式中

后续节点可通过 $("Send Email (SMTP)").item.json.<路径> 读取此节点输出中的内容(请把 Send Email (SMTP) 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 out 返回的路径,依据“端口”一节所示的输出。

表达式EditorWorker
$("Send Email (SMTP)").item.json.resultobject= {…}发送信息
$("Send Email (SMTP)").item.json.result.acceptedarray编辑器不提示= […] (1)—
$("Send Email (SMTP)").item.json.result.rejectedarray编辑器不提示= […] (0)—
$("Send Email (SMTP)").item.json.result.envelopeobject编辑器不提示= {…}—
$("Send Email (SMTP)").item.json.result.messageIdstring编辑器不提示= "<5f1c2a7e-8b1d-4a3e-9c0f-2d6e7b8a9c10@exampl…"—
$("Send Email (SMTP)").item.json.result.responsestring编辑器不提示= "250 2.0.0 OK queued"—

— Worker: worker 会返回它,但编辑器不会提示:请手动输入。对象内部的键可能取决于你的数据或配置(例如每个标签一个键)。

错误

消息 端口 原因与处理
to is required error 缺少收件人。to 可填写一个地址或以逗号分隔的多个地址。(connection_id is required 和 subject is required 对应其他必填字段。)
Invalid login: <server response> error 服务器拒绝了用户名或密码。要求应用专用密码的服务商需要在凭据中保存该密码。
<TLS or connection error> error secure 与端口不匹配:465 端口请使用 secure: true,587 端口请使用 secure: false(会自动协商 STARTTLS)。

输入契约

connection_id string 必填
to string 必填
subject string 必填
text string 可选
html string 可选

输出契约

result object 可选

发送信息

契约(JSON Schema)

与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。

{
  "slug": "io.smtp",
  "name": "Send Email (SMTP)",
  "category": "io",
  "version": "1.0.0",
  "description": "Send emails via SMTP server.",
  "capabilities": [
    "email",
    "smtp",
    "communication"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string",
        "title": "SMTP Credential",
        "description": "Credential for the SMTP server. Accepts credentials of type `basic-auth` (username + password + host + port) or `connection-string` (smtp:// / smtps:// URI).",
        "ui_widget": "connection_picker",
        "ui_options": {
          "credential_types": [
            "basic-auth",
            "connection-string"
          ],
          "types": [
            "smtp"
          ]
        }
      },
      "to": {
        "type": "string",
        "description": "Recipient email(s)"
      },
      "subject": {
        "type": "string"
      },
      "text": {
        "type": "string",
        "description": "Text body"
      },
      "html": {
        "type": "string",
        "description": "HTML body"
      }
    },
    "required": [
      "connection_id",
      "to",
      "subject"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string"
      },
      "to": {
        "type": "string"
      },
      "subject": {
        "type": "string"
      },
      "text": {
        "type": "string"
      },
      "html": {
        "type": "string"
      }
    },
    "required": [
      "connection_id",
      "to",
      "subject"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "result": {
        "type": "object",
        "description": "Send info"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Sent",
      "description": "Email accepted by relay",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Sending failed",
      "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
    }
  }
}

执行

执行方式
async
有状态
否
凭据
在服务器端根据 connection_id 解析,密钥不会进入工作流。
能力
emailsmtpcommunication
标签
emailcommunication

说明与限制

  • 此节点不支持附件、cc、bcc 和 replyTo。
  • out 表示中继已接受邮件,并不代表已送达收件箱。不具备幂等性:每次运行都会发送一封新邮件;不会重试。

已对照编排器代码核实 · 31e874b · 2026-11-26

安装智能体工具

为你的编程智能体接入 Sommatic AI 官方文档:技能包、文档 MCP 服务器与 Markdown 页面,无需再抓取网页。

安装 Sommatic AI CLI,并为检测到的智能体配置合适的插件。

npx @sommatic/cli agent setup
智能体如何读取本文档