첨부파일

파일을 업로드해 발신 이메일에 첨부하세요. 첨부파일이 있는 수신 이메일은 자동으로 저장되며 API로 접근 가능합니다.

개요

AgentSend는 양방향으로 파일 첨부를 처리합니다. 발신 이메일의 경우 먼저 파일을 업로드해 첨부파일 ID를 얻은 다음 메시지 전송 시 해당 ID를 전달합니다. 수신 이메일의 경우 발신자가 포함한 첨부파일이 자동으로 저장되어 메시지 객체에 노출됩니다 — 추가 작업이 필요 없습니다.

첨부파일은 안전하게 저장되며 단기 프리사인드 URL을 통해 제공됩니다. 다운로드 링크는 1시간 후 만료됩니다. 파일에 접근해야 할 때 API에서 새 URL을 가져오세요.

첨부파일 업로드

파일을 multipart/form-data/attachmentsPOST 요청을 보냅니다. 응답은 메시지 전송 시 사용할 수 있는 id를 포함한 첨부파일 객체를 반환합니다.

curl
curl -X POST https://api.agentsend.io/attachments \
  -H "x-api-key: $AGENTSEND_API_KEY" \
  -F "file=@/path/to/report.pdf"
javascript
const form = new FormData();
form.append("file", fileBlob, "report.pdf");

const res = await fetch("https://api.agentsend.io/attachments", {
  method: "POST",
  headers: { "x-api-key": process.env.AGENTSEND_API_KEY },
  body: form,
});

const attachment = await res.json();
console.log(attachment.id); // e.g. "att_a1b2c3d4"

첨부파일 속성

모든 첨부파일 객체에는 다음 필드가 포함됩니다:

필드 타입 설명
id string 고유 첨부파일 식별자 (접두사 att_).
filename string 업로드되거나 수신된 원본 파일명.
contentType string MIME 타입 (예: application/pdf 또는 image/png).
size number 파일 크기 (바이트).
url string 프리사인드 다운로드 URL. 1시간 후 만료.
createdAt string 첨부파일이 저장된 시각 (ISO 8601).

메시지에 첨부하기

전송 시 메시지 본문에 attachmentIds 배열을 전달합니다. 하나의 메시지에서 여러 첨부파일을 참조할 수 있습니다.

javascript
// 1. Upload the file
const form = new FormData();
form.append("file", fileBlob, "invoice.pdf");
const { id: attachmentId } = await fetch("https://api.agentsend.io/attachments", {
  method: "POST",
  headers: { "x-api-key": process.env.AGENTSEND_API_KEY },
  body: form,
}).then(r => r.json());

// 2. Send the message with the attachment
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: "Your invoice",
    bodyText: "Please find your invoice attached.",
    attachmentIds: [attachmentId],
  }),
});

첨부파일 가져오기

GET /attachments/{id}로 ID로 단일 첨부파일을 가져옵니다. 응답에는 파일을 다운로드하는 데 사용할 수 있는 새로운 프리사인드 url이 포함됩니다.

javascript
const attachment = await fetch(
  `https://api.agentsend.io/attachments/${attachmentId}`,
  { headers: { "x-api-key": process.env.AGENTSEND_API_KEY } }
).then(r => r.json());

// Download the file using the presigned URL
const fileData = await fetch(attachment.url).then(r => r.arrayBuffer());

수신 첨부파일

첨부파일이 있는 수신 이메일이 도착하면 AgentSend는 각 파일을 자동으로 저장합니다. 메시지 객체에는 attachments 배열이 포함됩니다. 각 항목에는 파일을 식별하고 다운로드하는 데 필요한 메타데이터가 들어 있습니다.

json — inbound message (excerpt)
{
  "id": "msg_xyz",
  "subject": "Here's the contract",
  "attachments": [
    {
      "id": "att_a1b2c3",
      "filename": "contract.pdf",
      "contentType": "application/pdf",
      "size": 204800
    }
  ]
}

수신 첨부파일을 다운로드하려면 idGET /attachments/{id}에 전달해 프리사인드 다운로드 URL을 받으세요. 위 첨부파일 가져오기 섹션에 설명되어 있습니다.

크기 제한

단일 첨부파일의 최대 크기는 25 MB입니다. 업로드와 수신 첨부 모두에 적용됩니다. 수신 이메일에서 이 제한을 초과하는 파일은 폐기되며 메시지에 축약 메모가 추가됩니다.

많은 수신 메일 서버도 자체 첨부파일 크기 제한(종종 10-25 MB)을 시행합니다. 최상의 전송 가능성을 위해 첨부파일을 작게 유지하거나 외부 호스팅 파일에 대한 링크를 고려하세요.