---
title: "Gửi email | Tajo"
description: "Gửi email giao dịch qua Brevo API"
url: https://tajo.io/vi/docs/email-messaging/transactional-email/send-email/
markdown: https://tajo.io/vi/docs/email-messaging/transactional-email/send-email.md
lang: vi-VN
author: "Set Noa"
author_url: https://tajo.io/vi/set-noa/
robots: noindex
---

Đăng ký quyền truy cập sớm

Nhập tên và địa chỉ email công việc của bạn. Chúng tôi sẽ gửi liên kết để xác nhận yêu cầu truy cập Tajo.

# Gửi email

[Set Noa](https://tajo.io/vi/set-noa/)

Gửi từng email giao dịch bằng endpoint `/v3/smtp/email`.

## Endpoint

```http
POST /v3/smtp/email
```

## Nội dung yêu cầu

### Email cơ bản

```json
{
  "sender": {
    "name": "Your App",
    "email": "noreply@yourapp.com"
  },
  "to": [
    {
      "email": "user@example.com",
      "name": "John Doe"
    }
  ],
  "subject": "Welcome to our service!",
  "htmlContent": "<html><body><h1>Welcome!</h1><p>Thank you for signing up.</p></body></html>"
}
```

### Email nâng cao

```json
{
  "sender": {
    "name": "Your App",
    "email": "noreply@yourapp.com"
  },
  "to": [
    {
      "email": "user@example.com",
      "name": "John Doe"
    }
  ],
  "cc": [
    {
      "email": "cc@example.com",
      "name": "CC User"
    }
  ],
  "bcc": [
    {
      "email": "bcc@example.com"
    }
  ],
  "subject": "Order Confirmation #{{order_id}}",
  "htmlContent": "<html><body><h1>Order Confirmed</h1><p>Your order {{order_id}} has been confirmed.</p></body></html>",
  "textContent": "Your order {{order_id}} has been confirmed.",
  "params": {
    "order_id": "12345"
  },
  "tags": ["transactional", "order-confirmation"],
  "headers": {
    "X-Custom-Header": "custom-value"
  }
}
```

## Ví dụ mã nguồn

### JavaScript/Node.js

```javascript
const brevo = require('@getbrevo/brevo');

const apiInstance = new brevo.TransactionalEmailsApi();
apiInstance.setApiKey(brevo.TransactionalEmailsApiApiKeys.apiKey, process.env.BREVO_API_KEY);

const sendEmail = async () => {
  const sendSmtpEmail = new brevo.SendSmtpEmail();

  sendSmtpEmail.subject = "Welcome to our service!";
  sendSmtpEmail.htmlContent = "<html><body><h1>Welcome!</h1></body></html>";
  sendSmtpEmail.sender = { name: "Your App", email: "noreply@yourapp.com" };
  sendSmtpEmail.to = [{ email: "user@example.com", name: "John Doe" }];

  try {
    const result = await apiInstance.sendTransacEmail(sendSmtpEmail);
    console.log('Email sent:', result);
    return result;
  } catch (error) {
    console.error('Error sending email:', error);
    throw error;
  }
};
```

### Python

```python
import sib_api_v3_sdk
from sib_api_v3_sdk.rest import ApiException

configuration = sib_api_v3_sdk.Configuration()
configuration.api_key['api-key'] = 'YOUR_API_KEY'

api_instance = sib_api_v3_sdk.TransactionalEmailsApi(sib_api_v3_sdk.ApiClient(configuration))

send_smtp_email = sib_api_v3_sdk.SendSmtpEmail(
    to=[{"email": "user@example.com", "name": "John Doe"}],
    sender={"name": "Your App", "email": "noreply@yourapp.com"},
    subject="Welcome to our service!",
    html_content="<html><body><h1>Welcome!</h1></body></html>"
)

try:
    api_response = api_instance.send_transac_email(send_smtp_email)
    print(api_response)
except ApiException as e:
    print("Exception when calling TransactionalEmailsApi->send_transac_email: %s\n" % e)
```

### cURL

```bash
curl -X POST "https://api.brevo.com/v3/smtp/email" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "api-key: YOUR_API_KEY" \
  -d '{
    "sender": {
      "name": "Your App",
      "email": "noreply@yourapp.com"
    },
    "to": [
      {
        "email": "user@example.com",
        "name": "John Doe"
      }
    ],
    "subject": "Welcome to our service!",
    "htmlContent": "<html><body><h1>Welcome!</h1></body></html>"
  }'
```

## Phản hồi

### Phản hồi thành công (201 Created)

```json
{
  "messageId": "<202301151234.12345@smtp-relay.mailin.fr>"
}
```

### Phản hồi lỗi

**Khóa API không hợp lệ (401)**

```json
{
  "code": "unauthorized",
  "message": "Invalid API key provided"
}
```

**Định dạng email không hợp lệ (400)**

```json
{
  "code": "invalid_parameter",
  "message": "Invalid email format in 'to' field"
}
```

**Vượt giới hạn tần suất (429)**

```json
{
  "code": "too_many_requests",
  "message": "Rate limit exceeded"
}
```

## Tham số

### Tham số bắt buộc

| Tham số | Kiểu | Mô tả |
| --- | --- | --- |
| `sender` | object | Thông tin người gửi |
| `to` | array | Mảng các đối tượng người nhận |
| `subject` | string | Dòng tiêu đề email |

### Tham số tùy chọn

| Tham số | Kiểu | Mô tả |
| --- | --- | --- |
| `htmlContent` | string | Nội dung HTML của email |
| `textContent` | string | Nội dung văn bản của email |
| `cc` | array | Người nhận CC |
| `bcc` | array | Người nhận BCC |
| `replyTo` | object | Địa chỉ trả lời |
| `attachments` | array | Tệp đính kèm |
| `params` | object | Tham số của mẫu email |
| `tags` | array | Thẻ email dùng để theo dõi |
| `headers` | object | Header tùy chỉnh |

## Biến trong mẫu email

Dùng biến mẫu trong tiêu đề và nội dung email:

```json
{
  "subject": "Welcome {{firstName}}!",
  "htmlContent": "<h1>Hello {{firstName}} {{lastName}}</h1>",
  "params": {
    "firstName": "John",
    "lastName": "Doe"
  }
}
```

## Tệp đính kèm

Thêm tệp đính kèm:

```json
{
  "attachments": [
    {
      "content": "base64_encoded_content",
      "name": "invoice.pdf"
    },
    {
      "url": "https://example.com/document.pdf",
      "name": "document.pdf"
    }
  ]
}
```

## Thực hành tốt nhất

1. **Luôn kèm cả nội dung HTML và văn bản** để cải thiện khả năng gửi đến hộp thư
2. **Dùng biến mẫu** thay vì ghép chuỗi nội dung
3. **Điền đầy đủ thông tin người gửi** để tránh bộ lọc thư rác
4. **Thêm thẻ** phục vụ theo dõi và phân tích
5. **Kiểm tra tính hợp lệ của địa chỉ email** trước khi gửi
6. **Xử lý lỗi khéo léo** bằng logic thử lại

## Giới hạn tần suất

- **Giới hạn tốc độ API**: ở mức general, mà mọi gói đều có, endpoint này cho phép 1.000 yêu cầu mỗi giây và 3.600.000 mỗi giờ. Mức advanced (Professional và Enterprise) cho phép 2.000 mỗi giây, và mức extended (Enterprise) cho phép 6.000.
- **Khối lượng gửi**: số email bạn có thể gửi do gói Brevo của bạn quyết định, tách biệt với giới hạn tốc độ.

Xem [Giới hạn tốc độ](https://tajo.io/vi/docs/rate-limits/) và [trang giới hạn tốc độ](https://developers.brevo.com/docs/api-limits) của Brevo.

## Theo dõi

Email gửi qua endpoint này được tự động theo dõi các chỉ số:

- Trạng thái gửi
- Tỷ lệ mở
- Theo dõi lượt nhấp
- Xử lý thư trả về

Xem phân tích chi tiết trong bảng điều khiển Brevo tại **Statistics** → **Transactional**.

## Endpoint liên quan

- Mẫu email
- Tệp đính kèm
- [Thống kê email](https://tajo.io/vi/docs/analytics-reporting/)
