IM
ZH-TW
文件首頁
選單
指南

傳送出站電子郵件

使用選購的內聯部分和配件對 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\"
      }
    ]
  }"

註釋

  • 出站發送是異步的並且由作業支援。
  • 空收件人集很快就會失敗。