Send

View as Markdown
# BizMail API 1.0 — Send Mail --- ## 🇬🇧 English > **Authentication required.** All requests must include a valid JWT access token obtained from `POST /api/1.0/auth/token`. --- ### Send Mail **`POST /api/1.0/mail/store`** Send a transactional email. Supports plain text, HTML content, and file attachments. #### Headers | Key | Value | Required | | --- | --- | --- | | Authorization | Bearer | ✅ | | Content-Type | multipart/form-data | ✅ | #### Body (multipart/form-data) | Field | Type | Required | Description | | --- | --- | --- | --- | | from | string | ✅ | Sender email address. Must be a valid email. Max 255 characters | | from_name | string | ✅ | Sender display name. Max 255 characters | | subject | string | ✅ | Email subject | | to | string or string\[\] | ✅ | Recipient email address. Accepts a single email string or an array (`to[]`) | | cc | string or string\[\] | ❌ | CC email address(es). Accepts a single email string or an array (`cc[]`) | | bcc | string or string\[\] | ❌ | BCC email address(es). Accepts a single email string or an array (`bcc[]`) | | text | string | ✅ \* | Plain text content. Required if `html` is not provided | | html | string | ✅ \* | HTML content. Required if `text` is not provided | | reply_to | string | ❌ | Reply-To email address | | attachments / attachments\[\] | file | ❌ | File attachment(s). Total size must not exceed **20MB** | > \* At least one of `text` or `html` must be provided. #### Example Request (JSON-style reference) ``` POST /api/1.0/mail/store Authorization: Bearer <access_token> Content-Type: multipart/form-data from = info@example.com from_name = My Company subject = Account Activation to[] = user@example.com text = Your account has been activated. html = <p class=&#x27;preserveHtml&#x27; class=&#x27;preserveHtml&#x27;>Your account has been activated.</p> attachments[] = [file] ``` #### PHP (Guzzle) Example ``` php $client = new Client(); $response = $client->post('https://smtp-api.bizfly.vn/api/1.0/mail/store', [ 'headers' => [ &#x27;Authorization&#x27; => &#x27;Bearer <access_token>&#x27;, ], 'multipart' => [ ['name' => 'from', 'contents' => 'info@example.com'], ['name' => 'from_name', 'contents' => 'My Company'], ['name' => 'subject', 'contents' => 'Account Activation'], ['name' => 'to[]', 'contents' => 'user@example.com'], ['name' => 'text', 'contents' => 'Your account has been activated.'], [&#x27;name&#x27; => &#x27;html&#x27;, &#x27;contents&#x27; => &#x27;<p class=&#x27;preserveHtml&#x27; class=&#x27;preserveHtml&#x27;>Your account has been activated.</p>&#x27;], [ 'name' => 'attachments[]', 'contents' => Utils::tryFopen('/path/to/file.pdf', 'r'), 'filename' => 'file.pdf', ], ], ]); ``` #### Responses **200 OK — Success** ``` json { "code": 200, "status": "Save mail success", "message_id": "550e8400-e29b-41d4-a716-446655440000@bizfly.vn" } ``` | Field | Type | Description | | --- | --- | --- | | code | integer | HTTP status code | | status | string | Result message | | message_id | string | Unique ID of the queued email | **400 Bad Request — Validation error** ``` json { "errors": [ { "msg": "Người gửi phải là email", "param": "from", "location": "body" } ] } ``` **400 Bad Request — Attachment too large** ``` json { "errors": [ { "msg": "Tổng dung lượng file upload tối đa là 20Mb", "param": "attachments", "location": "files" } ] } ``` **401 Unauthorized — Missing or invalid token** ``` json { "success": false, "message": "Missing or invalid Authorization header" } ``` **401 Unauthorized — Token expired** ``` json { "success": false, "message": "Access token expired" } ``` **500 Internal Server Error** ``` json { "success": false, "message": "Internal server error" } ``` --- --- ## 🇻🇳 Tiếng Việt > **Yêu cầu xác thực.** Tất cả request phải kèm JWT access token hợp lệ lấy từ `POST /api/1.0/auth/token`. --- ### Gửi Mail **`POST /api/1.0/mail/store`** Gửi email giao dịch. Hỗ trợ nội dung text thuần, HTML và file đính kèm. #### Headers | Key | Value | Bắt buộc | | --- | --- | --- | | Authorization | Bearer | ✅ | | Content-Type | multipart/form-data | ✅ | #### Body (multipart/form-data) | Tham số | Kiểu | Bắt buộc | Mô tả | | --- | --- | --- | --- | | from | string | ✅ | Email người gửi. Phải là email hợp lệ. Tối đa 255 ký tự | | from_name | string | ✅ | Tên hiển thị người gửi. Tối đa 255 ký tự | | subject | string | ✅ | Tiêu đề email | | to | string hoặc string\[\] | ✅ | Email người nhận. Có thể là 1 email string hoặc mảng (`to[]`) | | cc | string hoặc string\[\] | ❌ | Email CC. Có thể là 1 email string hoặc mảng (`cc[]`) | | bcc | string hoặc string\[\] | ❌ | Email BCC. Có thể là 1 email string hoặc mảng (`bcc[]`) | | text | string | ✅ \* | Nội dung dạng text thuần. Bắt buộc nếu không có `html` | | html | string | ✅ \* | Nội dung dạng HTML. Bắt buộc nếu không có `text` | | reply_to | string | ❌ | Địa chỉ email Reply-To | | attachments / attachments\[\] | file | ❌ | File đính kèm. Tổng dung lượng không vượt quá **20MB** | > \* Phải có ít nhất một trong `text` hoặc `html`. #### Ví dụ Request (dạng tham chiếu) ``` POST /api/1.0/mail/store Authorization: Bearer <access_token> Content-Type: multipart/form-data from = info@example.com from_name = Công ty của tôi subject = Kích hoạt tài khoản to[] = user@example.com text = Tài khoản của bạn đã được kích hoạt thành công. html = <p class=&#x27;preserveHtml&#x27; class=&#x27;preserveHtml&#x27;>Tài khoản của bạn đã được kích hoạt thành công.</p> attachments[] = [file] ``` #### Ví dụ PHP (Guzzle) ``` php $client = new Client(); $response = $client->post('https://smtp-api.bizfly.vn/api/1.0/mail/store', [ 'headers' => [ &#x27;Authorization&#x27; => &#x27;Bearer <access_token>&#x27;, ], 'multipart' => [ ['name' => 'from', 'contents' => 'info@example.com'], ['name' => 'from_name', 'contents' => 'Công ty của tôi'], ['name' => 'subject', 'contents' => 'Kích hoạt tài khoản'], ['name' => 'to[]', 'contents' => 'user@example.com'], ['name' => 'text', 'contents' => 'Tài khoản của bạn đã được kích hoạt thành công.'], [&#x27;name&#x27; => &#x27;html&#x27;, &#x27;contents&#x27; => &#x27;<p class=&#x27;preserveHtml&#x27; class=&#x27;preserveHtml&#x27;>Tài khoản của bạn đã được kích hoạt thành công.</p>&#x27;], [ 'name' => 'attachments[]', 'contents' => Utils::tryFopen('/path/to/file.pdf', 'r'), 'filename' => 'file.pdf', ], ], ]); ``` #### Responses **200 OK — Thành công** ``` json { "code": 200, "status": "Save mail success", "message_id": "550e8400-e29b-41d4-a716-446655440000@bizfly.vn" } ``` | Trường | Kiểu | Mô tả | | --- | --- | --- | | code | integer | HTTP status code | | status | string | Thông báo kết quả | | message_id | string | ID duy nhất của email đã được đưa vào hàng đợi gửi | **400 Bad Request — Lỗi validation** ``` json { "errors": [ { "msg": "Người gửi phải là email", "param": "from", "location": "body" } ] } ``` **400 Bad Request — File đính kèm quá lớn** ``` json { "errors": [ { "msg": "Tổng dung lượng file upload tối đa là 20Mb", "param": "attachments", "location": "files" } ] } ``` **401 Unauthorized — Thiếu hoặc sai token** ``` json { "success": false, "message": "Missing or invalid Authorization header" } ``` **401 Unauthorized — Token hết hạn** ``` json { "success": false, "message": "Access token expired" } ``` **500 Internal Server Error** ``` json { "success": false, "message": "Internal server error" } ```

Request

This endpoint expects a multipart form containing a file.
fromstringRequired
from_namestringRequired
subjectstringRequired
to[]stringRequired
textstringRequired
htmlstringRequired
attachments[]fileRequired

Response headers

x-powered-bystring
etagstring
front-end-httpsstring
strict-transport-securitystring

Response

OK
codeinteger
statusstring
message_idstringformat: "email"

Errors

400
Bad Request Error