สรุปโดยย่อ
API ของ Brevo ช่วยให้คุณสามารถส่งอีเมลการตลาด อีเมลธุรกรรม และข้อความ SMS ได้อย่างเป็นระบบ โดยยืนยันตัวตนด้วย API Key และใช้งานผ่าน api.brevo.com พร้อมรองรับ Webhook เพื่อติดตามสถานะการนำส่งและการมีส่วนร่วม ใช้ Apidog เพื่อตรวจสอบ Payload ทดสอบ Webhook และตรวจสอบการจัดการ Bounce/Unsubscribe ให้ถูกต้องก่อนขึ้น Production
บทนำ
Brevo (ชื่อเดิม Sendinblue) ให้บริการส่งอีเมลและ SMS แบบครบวงจรสำหรับธุรกิจกว่า 500,000 แห่ง รองรับทั้งแคมเปญการตลาด อีเมลธุรกรรม การตลาด SMS และเวิร์กโฟลว์อัตโนมัติ
API อีเมลที่ดีต้องรองรับการจัดการ Bounce, Spam Complaint, Unsubscribe และ Scheduling โดย Brevo จัดการสิ่งเหล่านี้ให้คุณ
API หลักครอบคลุม 3 กรณีใช้งาน:
- แคมเปญการตลาด - ส่งอีเมลจำนวนมากไปยัง Contact List
- อีเมลธุรกรรม - เช่น รีเซ็ตรหัสผ่าน, ยืนยันคำสั่งซื้อ, การแจ้งเตือน
- ข้อความ SMS - ส่งรหัสยืนยัน, แจ้งเตือน, และข้อความการตลาด
💡 หากคุณผสานรวมอีเมลเข้ากับแอปของคุณ ใช้ Apidog เพื่อทดสอบเทมเพลต ตรวจสอบ Payload ของ Webhook และยืนยันการทำงานกับไคลเอนต์อีเมลทุกประเภท สามารถจำลอง Response ของ Brevo เพื่อทดสอบ Error Handling โดยไม่ต้องส่งอีเมลจริง
การยืนยันตัวตนและการตั้งค่า
รับ API Key
- เข้าสู่ระบบ Brevo
- ไปที่ SMTP & API → API Keys
- สร้างคีย์ใหม่ พร้อมกำหนดสิทธิ์ตามต้องการ
- เก็บ API Key ไว้อย่างปลอดภัย
ตัวอย่างการใช้ API Key ใน Header:
curl -X GET "https://api.brevo.com/v3/account" \
-H "accept: application/json" \
-H "api-key: your-api-key-here"
Base URL ของ API
ทุก Request ใช้ Base URL ดังนี้:
https://api.brevo.com/v3/
ข้อจำกัดด้านอัตรา (Rate limits)
- ฟรี: 300 คำขอ/นาที
- Starter: 600 คำขอ/นาที
- Business: 1200 คำขอ/นาที
ตรวจสอบ Header X-RateLimit-Remaining สำหรับการติดตามการใช้
การส่งอีเมลธุรกรรม
อีเมลธุรกรรมเช่น รีเซ็ตรหัสผ่าน, ยืนยันคำสั่งซื้อ, Welcome Email
ส่งอีเมลง่ายๆ
curl -X POST "https://api.brevo.com/v3/smtp/email" \
-H "accept: application/json" \
-H "api-key: your-api-key" \
-H "content-type: application/json" \
-d '{
"sender": {
"name": "Your App",
"email": "noreply@yourapp.com"
},
"to": [
{
"email": "user@example.com",
"name": "John Doe"
}
],
"subject": "Welcome to Our Platform",
"htmlContent": "<html><body><h1>Welcome!</h1><p>Thanks for signing up.</p></body></html>",
"textContent": "Welcome! Thanks for signing up."
}'
Response:
{
"messageId": "<20260324123456.123456@relay.brevo.com>"
}
การใช้เทมเพลต
สร้างเทมเพลตใน Brevo แล้วเรียกใช้ด้วย templateId:
curl -X POST "https://api.brevo.com/v3/smtp/email" \
-H "api-key: your-api-key" \
-H "content-type: application/json" \
-d '{
"templateId": 15,
"to": [
{
"email": "user@example.com",
"name": "John Doe"
}
],
"params": {
"name": "John",
"order_number": "ORD-12345",
"tracking_url": "https://tracking.example.com/ORD-12345"
}
}'
ในเทมเพลตใช้ {{params.name}} สำหรับตัวแปร:
<p>Hi {{params.name}},</p>
<p>Your order {{params.order_number}} has shipped.</p>
<p><a href="{{params.tracking_url}}">Track your package</a></p>
ส่งพร้อมไฟล์แนบ
const response = await fetch('https://api.brevo.com/v3/smtp/email', {
method: 'POST',
headers: {
'api-key': process.env.BREVO_API_KEY,
'content-type': 'application/json'
},
body: JSON.stringify({
sender: { name: 'Your App', email: 'noreply@yourapp.com' },
to: [{ email: 'user@example.com' }],
subject: 'Your Invoice',
htmlContent: '<p>Please find your invoice attached.</p>',
attachment: [
{
name: 'invoice.pdf',
content: base64EncodedPdfContent
}
]
})
})
แคมเปญการตลาด
Brevo ช่วยจัดการแคมเปญอีเมลการตลาด ตั้งเวลา ส่งลิงก์ยกเลิกการสมัคร และวิเคราะห์สถิติ
สร้างแคมเปญ
curl -X POST "https://api.brevo.com/v3/emailCampaigns" \
-H "api-key: your-api-key" \
-H "content-type: application/json" \
-d '{
"name": "March Newsletter",
"subject": "What'\''s New in March",
"sender": {
"name": "Your Brand",
"email": "newsletter@yourbrand.com"
},
"type": "classic",
"htmlContent": "<html><body>Newsletter content here...</body></html>",
"recipients": {
"listIds": [12, 15]
},
"scheduledAt": "2026-03-25T09:00:00+00:00"
}'
ส่งทันที
curl -X POST "https://api.brevo.com/v3/emailCampaigns/{campaignId}/sendNow" \
-H "api-key: your-api-key"
รับสถิติแคมเปญ
curl -X GET "https://api.brevo.com/v3/emailCampaigns/{campaignId}" \
-H "api-key: your-api-key"
Response:
{
"statistics": {
"delivered": 4850,
"opened": 1455,
"clicked": 291,
"unsubscribed": 12,
"bounces": 150
}
}
การจัดการผู้ติดต่อ
จัดระเบียบผู้ติดต่อในรายการ เพิ่ม/อัปเดตข้อมูล และควบคุม status
สร้างผู้ติดต่อ
curl -X POST "https://api.brevo.com/v3/contacts" \
-H "api-key: your-api-key" \
-H "content-type: application/json" \
-d '{
"email": "new.user@example.com",
"attributes": {
"FIRSTNAME": "Jane",
"LASTNAME": "Smith",
"PLAN": "premium"
},
"listIds": [12, 15],
"updateEnabled": true
}'
updateEnabled: true จะอัปเดตผู้ติดต่อที่มีอยู่
ดูรายละเอียดผู้ติดต่อ
curl -X GET "https://api.brevo.com/v3/contacts/user@example.com" \
-H "api-key: your-api-key"
เพิ่มเข้าในรายการ
curl -X POST "https://api.brevo.com/v3/contacts/lists/12/contacts/add" \
-H "api-key: your-api-key" \
-H "content-type: application/json" \
-d '{
"emails": ["user1@example.com", "user2@example.com"]
}'
ลบออกจากรายการ
curl -X DELETE "https://api.brevo.com/v3/contacts/lists/12/contacts/remove" \
-H "api-key: your-api-key" \
-H "content-type: application/json" \
-d '{
"emails": ["user@example.com"]
}'
ยกเลิกการสมัครของผู้ติดต่อ
curl -X PUT "https://api.brevo.com/v3/contacts/user@example.com" \
-H "api-key: your-api-key" \
-H "content-type: application/json" \
-d '{
"emailBlacklisted": true
}'
การตลาด SMS
Brevo รองรับการส่ง SMS ทั่วโลกผ่าน API
ส่ง SMS
curl -X POST "https://api.brevo.com/v3/transactionalSMS/sms" \
-H "api-key: your-api-key" \
-H "content-type: application/json" \
-d '{
"sender": "YourApp",
"recipient": "+15551234567",
"content": "Your verification code is: 123456",
"type": "transactional"
}'
ส่ง SMS การตลาด
curl -X POST "https://api.brevo.com/v3/transactionalSMS/sms" \
-H "api-key: your-api-key" \
-H "content-type: application/json" \
-d '{
"sender": "YourBrand",
"recipient": "+15551234567",
"content": "Flash sale! 50% off today only. Reply STOP to unsubscribe.",
"type": "marketing"
}'
ดูสถิติ SMS
curl -X GET "https://api.brevo.com/v3/transactionalSMS/statistics?startDate=2026-03-01&endDate=2026-03-31" \
-H "api-key: your-api-key"
Webhooks สำหรับการติดตาม
Webhook จะส่ง event ไปยังแอปของคุณทันทีที่เกิดเหตุการณ์ เช่น ส่งถึง, เปิดอ่าน, คลิก, ตีกลับ, ยกเลิกการสมัคร
กำหนดค่า Webhooks
ใน Dashboard Brevo: การตั้งค่า → Webhooks → เพิ่ม Webhook
เหตุการณ์ที่เลือกติดตาม:
deliveredopenedclickedbouncedspamunsubscribed
จัดการ Payload ของ Webhook
app.post('/webhooks/brevo', (req, res) => {
const event = req.body
switch (event.event) {
case 'delivered':
console.log(`Email ${event.messageId} delivered to ${event.email}`)
break
case 'opened':
console.log(`Email opened by ${event.email} at ${event.date}`)
break
case 'bounced':
console.log(`Bounce: ${event.email} - ${event.reason}`)
// ทำเครื่องหมายผู้ติดต่อว่าไม่ถูกต้อง
markContactBounced(event.email)
break
case 'spam':
console.log(`Spam complaint from ${event.email}`)
// ลบออกจากรายการทั้งหมด
removeFromAllLists(event.email)
break
case 'unsubscribed':
console.log(`Unsubscribed: ${event.email}`)
break
}
res.status(200).send('OK')
})
การทดสอบด้วย Apidog
API การส่งอีเมลมักมีโหมด error ที่ซับซ้อน จำเป็นต้องทดสอบทั้ง Template, Bounce, Webhook ใช้ Apidog เพื่อจัดการ
1. การจำลองการส่งอีเมล
ระหว่าง dev ใช้ mock response แทนการส่งจริง:
pm.test('Email API accepts valid payload', () => {
const response = pm.response.json()
pm.expect(response).to.have.property('messageId')
pm.expect(response.messageId).to.match(/<.*@relay\.brevo\.com>/)
})
2. ทดสอบการจัดการ Webhook
สร้าง payload จำลองใน Apidog:
{
"event": "bounced",
"email": "invalid@example.com",
"messageId": "<12345@relay.brevo.com>",
"reason": "hard_bounce",
"date": "2026-03-24T12:00:00Z",
"subject": "Welcome to Our Platform"
}
ส่งไปยัง Endpoint ของคุณ แล้วตรวจสอบการ handle event
3. ตรวจสอบความถูกต้องของเทมเพลต
ทดสอบว่า params ใน payload ถูกแทนที่ครบ:
pm.test('Template variables are valid', () => {
const payload = pm.request.body.toJSON()
pm.expect(payload.params).to.have.property('name')
pm.expect(payload.params).to.have.property('order_number')
})
4. การแยกสภาพแวดล้อม
# การพัฒนา
BREVO_API_KEY: xkeysib-dev-xxx
BREVO_SENDER: dev@yourapp.com
# การใช้งานจริง
BREVO_API_KEY: xkeysib-prod-xxx
BREVO_SENDER: noreply@yourapp.com
ทดสอบ Brevo email APIs ด้วย Apidog - ฟรี
ข้อผิดพลาดทั่วไปและการแก้ไข
400 Bad Request - ข้อมูลที่จำเป็นขาดหายไป
สาเหตุ: ข้อมูลใน payload ไม่ครบ
วิธีแก้: อ่าน error message
{
"code": "invalid_parameter",
"message": "sender.email is required"
}
401 Unauthorized (ไม่ได้รับอนุญาต)
สาเหตุ: API Key ผิดหรือขาด
วิธีแก้: ตรวจสอบ header api-key และสถานะ key
402 Payment Required (ต้องชำระเงิน)
สาเหตุ: เกินขีดจำกัด/เครดิตหมด
วิธีแก้:
- สำหรับอีเมล: ตรวจสอบ quota ของ plan
- สำหรับ SMS: เติมเครดิต
429 Too Many Requests (คำขอมากเกินไป)
สาเหตุ: เกิน rate limit
วิธีแก้: ใช้ Exponential Backoff
async function sendWithRetry(email, retries = 3) {
for (let i = 0; i < retries; i++) {
const response = await sendEmail(email)
if (response.status === 429) {
await sleep(Math.pow(2, i) * 1000)
} else {
return response
}
}
throw new Error('Rate limit exceeded')
}
404 Contact not found (ไม่พบผู้ติดต่อ)
สาเหตุ: ไม่มี contact
วิธีแก้: ใช้ updateEnabled: true เมื่อสร้าง
{
"email": "new@example.com",
"updateEnabled": true
}
ทางเลือกและการเปรียบเทียบ
| คุณสมบัติ | Brevo | SendGrid | Mailchimp | Postmark |
|---|---|---|---|---|
| ราคา | ฟรี 300 อีเมล/วัน | ฟรี 100 อีเมล/วัน | ฟรี 500 อีเมล/เดือน | ฟรี 100 อีเมล/เดือน |
| อีเมลการตลาด | ใช่ | ใช่ | ใช่ | ไม่ |
| อีเมลธุรกรรม | ใช่ | ใช่ | จำกัด | ใช่ (เฉพาะทาง) |
| SMS | ใช่ | ไม่ | ไม่ | ไม่ |
| ระบบอัตโนมัติ | ใช่ | ใช่ | ใช่ | จำกัด |
| ตัวแก้ไขเทมเพลต | แบบภาพ + โค้ด | โค้ด | แบบภาพ | โค้ด |
Brevo โดดเด่นที่รองรับ Email และ SMS ในราคาที่แข่งขัน
กรณีการใช้งานจริง
- E-commerce: อีเมลยืนยันคำสั่งซื้อ, แจ้งส่งของ, กู้คืนตะกร้าค้าง, โปรโมชัน—all ผ่าน API เดียว
- SaaS: ส่ง welcome, reset password, ทีมเชิญ ผ่าน API ธุรกรรม อีเมล marketing สำหรับแจ้งฟีเจอร์ใหม่
- SMS Verification: ฟินเทคใช้ SMS API สำหรับ 2FA พร้อม webhook ติดตาม delivery/failure
สรุป
สิ่งที่ควรนำไปใช้:
- API ของ Brevo รองรับอีเมลการตลาด ธุรกรรม และ SMS
- ยืนยันตัวตนด้วย header
api-key - ใช้เทมเพลตเพื่อความสอดคล้อง
- บริหารจัดการ contact และรายชื่อ
- ใช้ Webhook เพื่อติดตาม delivery, open, click, bounce
- ทดสอบกับ Apidog ก่อนขึ้น production
ขั้นตอนถัดไป:
- สร้างบัญชี Brevo และขอ API Key
- ทดสอบส่งอีเมลธุรกรรมฉบับแรก
- สร้างเทมเพลตใน Editor
- ตั้งค่า Webhook สำหรับ bounce/unsubscribe
- ทดสอบทุกอย่างด้วย Apidog
คำถามที่พบบ่อย
Brevo และ Sendinblue ต่างกันอย่างไร?
เป็นผลิตภัณฑ์เดียวกัน เปลี่ยนชื่อในปี 2023 API ยังคงใช้ api.brevo.com แต่เอกสารเก่าอาจยังมีชื่อ Sendinblue
ส่งอีเมลฟรีได้กี่ฉบับ?
300 ต่อวันในแผนฟรี (9,000/เดือน) ถ้าต้องการมากขึ้น อัปเกรดเริ่มต้น $25/เดือน (20,000 อีเมล)
ใช้ Brevo ส่ง Cold Email ได้ไหม?
ทางเทคนิคทำได้ แต่เสี่ยงสูงต่อ bounce/complaint และอาจโดนระงับบัญชี ควรปฏิบัติตาม best practice
จัดการอีเมล bounce อย่างไร?
รอฟัง event bounced จาก webhook
- Hard bounce: ลบ contact ทันที
- Soft bounce: สามารถ retry
- Bounce rate เกิน 5% โดเมนคุณจะเสียชื่อเสียง
ต่างกันอย่างไรระหว่างอีเมลธุรกรรมและการตลาด?
ธุรกรรม = ทริกเกอร์โดย action ของ user
การตลาด = ส่งเป็นชุดใหญ่ Brevo แยกประเภทนี้เพื่อปรับการ deliver
เพิ่มลิงก์ Unsubscribe ได้อย่างไร?
อีเมลการตลาด Brevo ใส่อัตโนมัติ
อีเมลธุรกรรม ให้เพิ่มเอง:
<a href="{{ unsubscribe_url }}">Unsubscribe</a>
ส่งอีเมลจาก domain ตัวเองได้ไหม?
ทำได้ ต้องตั้งค่า SPF, DKIM, DMARC ดูค่าจาก Brevo ใน Setting → ผู้ส่งและ IP
ตั้งเวลาอีเมลใน timezone เฉพาะได้ไหม?
ใช้ scheduledAt เป็น ISO 8601
{
"scheduledAt": "2026-03-25T09:00:00-05:00"
}
หากเจอ Rate Limit จะเกิดอะไร?
จะได้ error 429 พร้อม header X-RateLimit-Reset (วินาทีก่อนรีเซ็ต) ใช้ exponential backoff หรือ queue job รอส่งใหม่


Top comments (0)