邮件模板
Email Template 定义可复用的邮件内容,并通过变量占位符({{variable}})实现动态个性化。
Schema
interface EmailTemplate {
id: string; // "emt_..." - Unique identifier
account_id: string; // Owning account
name: string; // Template name
event_type: string; // Business event (e.g., "user_welcome")
editor: "grapesjs_mjml"; // Template editor
editor_state: string; // Serialized editor state
mjml: string; // MJML source
subject_template: string; // Subject with variables
body_text_template: string; // Plain text with variables
body_html_template: string; // HTML with variables
archived_at: string | null; // Archived timestamp
}
属性
| 属性 | 类型 | 说明 |
|---|---|---|
id | string | 带 emt_ 前缀的 KSUID |
account_id | string | 拥有该模板的账户 |
name | string | 可读模板名称 |
event_type | string | 业务事件触发名 |
editor | string | 编辑器类型 |
editor_state | string | 序列化编辑器状态 |
mjml | string | MJML 源码 |
subject_template | string | 主题模板 |
body_text_template | string | 纯文本正文模板 |
body_html_template | string | HTML 正文模板 |
archived_at | string? | 归档时间戳 |
变量语法
使用 {{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 - 已发送消息
- 邮件 - 邮件基础设施