Email Template
Email Template นิยามเนื้อหาอีเมลที่ใช้ซ้ำได้ พร้อมตัวแปรแทนค่า ({{variable}}) เพื่อปรับแต่งเนื้อหาแบบไดนามิก
สคีมา
interface EmailTemplate {
id: string; // "emt_..." - ตัวระบุที่ไม่ซ้ำ
account_id: string; // บัญชีเจ้าของ
name: string; // ชื่อเทมเพลต
event_type: string; // เหตุการณ์ทางธุรกิจ (เช่น "user_welcome")
editor: "grapesjs_mjml"; // ตัวแก้ไขเทมเพลต
editor_state: string; // สถานะ editor ที่ serialize แล้ว
mjml: string; // แหล่งที่มา MJML
subject_template: string; // หัวเรื่องพร้อมตัวแปร
body_text_template: string; // ข้อความล้วนพร้อมตัวแปร
body_html_template: string; // HTML พร้อมตัวแปร
archived_at: string | null; // เวลาที่ archive
}
คุณสมบัติ
| Property | Type | คำอธิบาย |
|---|---|---|
id | string | KSUID ที่ขึ้นต้นด้วย emt_ |
account_id | string | บัญชีที่เป็นเจ้าของเทมเพลต |
name | string | ชื่อที่อ่านเข้าใจได้ |
event_type | string | ชื่อเหตุการณ์ที่ใช้ทริกเกอร์ |
editor | string | ประเภท editor |
editor_state | string | สถานะ editor ที่ serialize แล้ว |
mjml | string | แหล่งที่มา MJML |
subject_template | string | เทมเพลตหัวเรื่อง |
body_text_template | string | เทมเพลตเนื้อหาแบบข้อความล้วน |
body_html_template | string | เทมเพลตเนื้อหาแบบ HTML |
archived_at | string? | เวลา archive |
ไวยากรณ์ตัวแปร
ใช้ {{variable_name}} สำหรับแทนค่า:
Subject: Welcome, {{name}}!
Dear {{name}},
Your account {{account_name}} is ready.
Best regards,
The {{company}} Team
การใช้งาน
ส่งผ่านเทมเพลต:
{
"template_id": "emt_...",
"to": [{ "email": "user@example.com" }],
"variables": {
"name": "Jane",
"account_name": "Acme Corp",
"company": "Example Inc"
}
}
ตัวอย่าง
{
"id": "emt_2kHfPZcN9xW4mE8RtY7vB",
"account_id": "acc_1jGePYbM8wV3lD7QsX6uA",
"name": "welcome",
"event_type": "user_welcome",
"editor": "grapesjs_mjml",
"editor_state": "{}",
"mjml": "<mjml><mj-body></mj-body></mjml>",
"subject_template": "Welcome to {{company}}, {{name}}!",
"body_text_template": "Hi {{name}},\n\nWelcome to {{company}}...",
"body_html_template": "<h1>Welcome, {{name}}!</h1>...",
"archived_at": null
}
ที่เกี่ยวข้อง
- Email Message - ข้อความที่ส่ง
- Email - โครงสร้างพื้นฐานอีเมล