The SDK exposes two rendering surfaces: a full-control render() method and three convenience shorthand methods.
Convenience methods
The fastest way to render. Each returns the output string directly.
// Render as HTML
const html = await client.renderHtml("template-id")
// Render as React Email (TSX)
const tsx = await client.renderReact("template-id")
// Render as MJML
const mjml = await client.renderMjml("template-id")
All three accept an optional dynamicData argument:
const html = await client.renderHtml("template-id", {
merge_tags: { text: { name: "Noruwa" } },
context: { plan: "pro" },
})
render() — full control
Use render() when you need access to the full result object or want to specify the target programmatically.
const result = await client.render({
templateId: "550e8400-e29b-41d4-a716-446655440000",
target: "html", // "html" | "react-email" | "mjml"
dynamicData: {
merge_tags: { text: { name: "Noruwa" } },
context: { plan: "pro" },
},
})
console.log(result.output) // rendered string
console.log(result.target) // "html"
console.log(result.templateId) // "550e8400-..."
RenderOptions
| Field | Type | Required | Description |
|---|---|---|---|
|
|
✓ |
The template to render. |
|
|
|
|
|
|
Merge tags and context values. See Dynamic Data. |
Choosing a target dynamically
import type { RenderTarget } from "maildeno"
async function render(templateId: string, target: RenderTarget, name: string) {
return client.render({
templateId,
target,
dynamicData: {
merge_tags: { text: { name } },
},
})
}
const html = await render("template-id", "html", "Noruwa")
const react = await render("template-id", "react-email", "Noruwa")
const mjml = await render("template-id", "mjml", "Noruwa")