> ## Documentation Index
> Fetch the complete documentation index at: https://docs.robase.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Email templates

> Reusable HTML + text + subject, server-rendered with Go templates.

Email templates work the same way as [SMS templates](/sms/templates), except each template has three fields — `subject`, `html`, and `text` — and the HTML body is rendered with Go's `html/template` (auto-escaping) while `subject` and `text` use `text/template`.

## Create a template

```typescript theme={null}
await pm.templates.create({
  name: 'Booking confirmation',
  subject: 'Your {{.ride_type}} ride is confirmed — {{.time}}',
  html: `
    <p>Hi {{.name}},</p>
    <p>Your ride is confirmed for {{.time}}.</p>
    <p><strong>Driver:</strong> {{.driver_name}}<br>
       <strong>Plate:</strong> {{.plate}}</p>
  `,
  text: `Hi {{.name}},\nYour ride is confirmed for {{.time}}.\nDriver: {{.driver_name}}\nPlate: {{.plate}}\n`,
});
```

## Send from a template

`POST /v1/templates/:id/render` previews rendering; to send, use `POST /v1/emails` with the template variables merged in before calling (current MVP — native `template` field on `/v1/emails` is on the roadmap alongside SMS's).

## Auto-escaping

HTML rendering escapes `<`, `>`, `&` so user-supplied data can't inject tags. Subject and text are rendered raw — don't put untrusted input in the subject without sanitization.

## Preview

```typescript theme={null}
const preview = await pm.templates.render('tpl_01H8...', {
  variables: { name: 'Chidi', time: '10:00am', driver_name: 'Amaka', plate: 'ABC 123 XY', ride_type: 'Airport' },
});
console.log(preview.subject, preview.html, preview.text);
```
