ข้อความ

ข้อความแทนอีเมลแต่ละฉบับที่ส่งหรือรับโดยกล่องจดหมาย ส่งอีเมล HTML ที่หลากหลาย ติดตามสถานะการส่ง และอ่านการตอบกลับขาเข้า

ภาพรวม

ข้อความคืออีเมลหนึ่งฉบับที่เชื่อมโยงกับกล่องจดหมาย เมื่อเอเจนต์ของคุณส่งอีเมล จะสร้างข้อความขาออก เมื่อมีคนตอบกลับหรือส่งอีเมลไปยังที่อยู่ของเอเจนต์ ข้อความขาเข้าจะถูกสร้างโดยอัตโนมัติ

ข้อความทุกข้อความเป็นของชุดสนทนา — อย่างใดอย่างหนึ่งที่มีอยู่แล้ว (สำหรับการตอบกลับ) หรือชุดสนทนาใหม่ที่สร้างโดยอัตโนมัติเมื่อเริ่มการสนทนาใหม่

ข้อความเป็นแบบ immutable เมื่อสร้างแล้ว หากต้องการส่งการติดตามผล ให้สร้างข้อความใหม่ในชุดสนทนาเดิมโดยส่ง threadId

การส่งอีเมล

POST /inboxes/{inboxId}/messages

ส่งอีเมลจากกล่องจดหมายโดย post ไปยัง endpoint ข้อความ อาร์เรย์ to และ subject จำเป็น ทุกสิ่งอื่นเป็นตัวเลือก

Request Body

ฟิลด์ ประเภท คำอธิบาย
to จำเป็น string[] อาร์เรย์ของที่อยู่อีเมลผู้รับ
subject จำเป็น string หัวข้ออีเมล
cc string[] ผู้รับ CC
bcc string[] ผู้รับ BCC ไม่แสดงให้ผู้รับอื่นเห็น
bodyText string เนื้อหาข้อความธรรมดา ใช้เป็น fallback เมื่อมี bodyHtml ด้วย
bodyHtml string เนื้อหา HTML เมื่อให้ทั้ง bodyText และ bodyHtml อีเมลจะถูกส่งเป็น multipart/alternative
threadId string ชุดสนทนาที่จะตอบกลับ หากละเว้น จะสร้างชุดสนทนาใหม่
attachmentIds string[] ID ของไฟล์แนบที่อัปโหลดไว้ก่อนหน้านี้เพื่อรวมไว้
javascript
const res = await fetch(
  `https://api.agentsend.io/inboxes/${inboxId}/messages`,
  {
    method: "POST",
    headers: {
      "x-api-key": process.env.AGENTSEND_API_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      to: ["customer@example.com"],
      subject: "ติดตามคำขอของคุณ",
      bodyText: "สวัสดี เพียงติดตามคำขอของคุณ",
      bodyHtml: "<p>สวัสดี เพียงติดตามคำขอของคุณ</p>",
    }),
  }
);

const message = await res.json();
console.log(message.id);     // msg_abc123
console.log(message.delivery); // "email" หรือ "dry-run"
console.log(message.status); // "queued"

Message Properties

Each message object returned by the API has the following fields.

คุณสมบัติ ประเภท คำอธิบาย
id string Unique message identifier.
inboxId string The inbox this message belongs to.
threadId string The conversation thread this message is grouped into.
direction string outbound for emails your agent sent; inbound for emails received.
fromAddress string Sender email address.
toAddresses string[] Primary recipients.
ccAddresses string[] CC recipients.
subject string Email subject line.
bodyText string Plain-text body content.
bodyHtml string HTML body content.
delivery string Whether the environment sent real email (email) or only simulated it (dry-run).
status string Current delivery status. See Message Status below.
attachments object[] Array of attachment objects with id, filename, contentType, and size.
messageIdHeader string The RFC 5322 Message-ID header value, used for threading in email clients.
createdAt string ISO 8601 timestamp of when the message was created.

Message Status

Outbound messages move through a delivery lifecycle. Check delivery first to confirm whether the environment sent real mail or only simulated it, then use status or webhooks to follow the provider-side lifecycle.

Outbound lifecycle

Failed states

Inbound messages

If a message reaches bounced or complained status, avoid sending further emails to that address to protect your sender reputation.

Listing Messages

GET /inboxes/{inboxId}/messages

Retrieve a paginated list of messages for an inbox. Filter by status to find inbound replies, failed sends, or any other subset.

Query Param ประเภท คำอธิบาย
limit number Number of messages to return. Defaults to 20, max 100.
offset number Number of messages to skip for pagination. Defaults to 0.
status string Filter by status. One of queued, sending, sent, delivered, failed, bounced, complained, received.
javascript
// Fetch the 10 most recent inbound messages
const res = await fetch(
  `https://api.agentsend.io/inboxes/${inboxId}/messages?status=received&limit=10`,
  { headers: { "x-api-key": process.env.AGENTSEND_API_KEY } }
);

const { data, total } = await res.json();

for (const msg of data) {
  console.log(msg.fromAddress, msg.subject, msg.bodyText);
}
💡

Use webhooks instead of polling to get notified the moment a new message arrives. Polling is a good fallback for simple scripts and short-lived tasks.

HTML vs Plain Text

AgentSend supports plain-text, HTML, and multipart emails. Use bodyText for plain text and bodyHtml for HTML content.

💡

Always include a bodyText version alongside bodyHtml. This improves deliverability, accessibility, and compatibility with plain-text email clients.

Deleting Messages

DELETE /messages/{id}

Delete a message by its ID. This removes the message record from AgentSend. It does not recall an already-delivered email from the recipient's mailbox.

javascript
await fetch(`https://api.agentsend.io/messages/${messageId}`, {
  method: "DELETE",
  headers: { "x-api-key": process.env.AGENTSEND_API_KEY },
});

Deleting a message is permanent. Inbound messages that are part of an active thread should be deleted with care, as the thread history will be incomplete.