IM
ZH-CN
文档首页
菜单
指南

发送出站电子邮件

使用可选的内联部分和附件对 SMTP 发送操作进行排队。

inbox-manager client-flow

发送出站电子邮件

目的:使用可选的内联部分和附件将 SMTP 发送操作排入队列。

用户界面流程

  1. 用户撰写消息。
  2. UI 捕获收件人、主题、正文、附件。
  3. UI 将POST /api/accounts/:account_id/smtp/messages 入队。
  4. UI 跟踪生成的任务/作业直至完成。
  5. UI 刷新出站电子邮件列表。

客户端库流程

const queued = await api.provider.smtp.sendMessage(accountId, {
  credential_id: smtpCredentialId,
  direction: "outbound",
  from_json: [{ address: "info@example.com" }],
  to_json: [{ address: "recipient@example.com" }],
  subject: "Status update",
  text_body: "Hello from Inbox Manager",
  html_body: "<p>Hello from Inbox Manager</p>",
  attachments: [
    {
      filename: "report.txt",
      content_type: "text/plain",
      content_b64: Buffer.from("report body").toString("base64"),
      disposition: "attachment",
    },
  ],
});
await api.jobs.waitForTask(accountId, queued.data.task_id);

HTTP/curl 流程

API_BASE_URL="https://api.inbox-manager.com"

curl -sS -X POST "${API_BASE_URL}/api/accounts/${ACCOUNT_ID}/smtp/messages" \
  -H "authorization: Bearer ${BEARER_TOKEN}" \
  -H "content-type: application/json" \
  --data "{
    \"credential_id\":\"${SMTP_CREDENTIAL_ID}\",
    \"direction\":\"outbound\",
    \"from_json\":[{\"address\":\"${FROM_ADDRESS}\"}],
    \"to_json\":[{\"address\":\"${TO_ADDRESS}\"}],
    \"subject\":\"Status update\",
    \"text_body\":\"Hello from Inbox Manager\",
    \"attachments\":[
      {
        \"filename\":\"report.txt\",
        \"content_type\":\"text/plain\",
        \"content_b64\":\"${ATTACHMENT_B64}\",
        \"disposition\":\"attachment\"
      }
    ]
  }"

注释

  • 出站发送是异步的并且由作业支持。
  • 空收件人集很快就会失败。