# EMAIL_TEMPLATE_RENDER_FAILED

<!-- Generated by docs/modules/diagnostics from the package catalogs. Write a guide in docs/diagnostics/<CODE>.md instead of editing this file. -->

`email.send({ template, data })` returns `EMAIL_TEMPLATE_RENDER_FAILED`. The template under `server/emails` did not render with `data`, so ViteHub did not send the message.

## Why it happens

`error.cause` is the error of the Markdown renderer, and its message names the binding. For example, `data.user.name` is missing, is `null`, or is an object. TypeScript catches these cases when the type of `data` is known. They happen at runtime when `data` comes from a request body, a database row, or a value typed as `unknown`.

## Fix it

Pass a string, number, or boolean for each `{{ data.* }}` binding, and a string for each `:insert` binding. A value that the template reads only inside an `::if` branch can be missing.

```diff [server/welcome.ts]
 const [error] = await email.send({
   template: 'welcome',
-  data: { user },
+  data: { user: { name: user.name ?? 'there' } },
   from: 'hello@example.com',
   to,
   subject: 'Welcome',
 })
```

Do not retry the same message. It fails the same way until `data` changes.

## Check the fix

Run `vitehub email preview welcome --data '{"user":{"name":"Ada"}}'` with the same `data`. It renders the template without sending it, and fails with the same binding when `data` does not fit.

## Related

- [Send a template](https://vitehub.dev/docs/email/server-api#send-a-template)
- [`EMAIL_TEMPLATE_NOT_FOUND`](https://vitehub.dev/docs/email/diagnostics/email_template_not_found)
- [Email limits and errors](https://vitehub.dev/docs/email/limits-and-errors)

## Source

`EMAIL_TEMPLATE_RENDER_FAILED` belongs to the `email` package. Its catalog entry is in [`src/error-diagnostics.ts`](https://github.com/vite-hub/vitehub/blob/main/packages/email/src/error-diagnostics.ts#L44). It is raised in [`src/runtime/email.ts`](https://github.com/vite-hub/vitehub/blob/main/packages/email/src/runtime/email.ts#L38).

See [all Email diagnostics](https://vitehub.dev/docs/email/diagnostics).

<!-- vitehub-docs:section-links -->
## In this section

- [Overview](https://vitehub.dev/raw/docs/email.md)
- [Get started](https://vitehub.dev/raw/docs/email/get-started.md)
- [Configure](https://vitehub.dev/raw/docs/email/configure.md)
- [Server API](https://vitehub.dev/raw/docs/email/server-api.md)
- [Agent capability](https://vitehub.dev/raw/docs/email/agent-capability.md)
- [Hosts](https://vitehub.dev/raw/docs/email/hosts.md)
- [Limits and errors](https://vitehub.dev/raw/docs/email/limits-and-errors.md)

Next: [Hosts](https://vitehub.dev/raw/docs/email/hosts.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
