Server API
Render Email
POST /api/emails/render - Render email templates to HTML
The /api/emails/render
endpoint allows you to render Vue email templates into HTML strings with optional plain text conversion.
Endpoint
POST /api/emails/render
Request Body
The endpoint accepts a JSON payload with the following structure:
Parameter | Type | Required | Description |
---|---|---|---|
name | string | ✅ | The name of the email template (without .vue extension) |
props | object | ❌ | Props to pass to the Vue component |
pretty | boolean | ❌ | Whether to format the output HTML (default: false) |
plainText | boolean | ❌ | Whether to include plain text version (default: false) |
htmlToTextOptions | object | ❌ | Options for HTML to text conversion |
Request Schema
interface RenderEmailRequest {
name: string;
props?: Record<string, any>;
pretty?: boolean;
plainText?: boolean;
htmlToTextOptions?: HtmlToTextOptions;
}
Response
The endpoint returns different response formats based on the plainText
parameter:
HTML Only Response (default)
When plainText
is false
or not provided:
{
"html": "<html>...</html>"
}
HTML + Plain Text Response
When plainText
is true
:
{
"html": "<html>...</html>",
"text": "Plain text version..."
}
Examples
Basic Usage
Render a simple welcome email:
curl -X POST http://localhost:3000/api/emails/render \
-H "Content-Type: application/json" \
-d '{
"name": "WelcomeEmail"
}'
Response:
{
"html": "<html><head></head><body><div>Welcome!</div></body></html>"
}
With Props
Render an email with dynamic content:
curl -X POST http://localhost:3000/api/emails/render \
-H "Content-Type: application/json" \
-d '{
"name": "WelcomeEmail",
"props": {
"userName": "John Doe",
"confirmationUrl": "https://example.com/confirm/abc123"
}
}'
Response:
{
"html": "<html><head></head><body><div>Welcome John Doe!</div><a href=\"https://example.com/confirm/abc123\">Confirm</a></body></html>"
}
Pretty Formatted HTML
Get formatted HTML output:
curl -X POST http://localhost:3000/api/emails/render \
-H "Content-Type: application/json" \
-d '{
"name": "WelcomeEmail",
"pretty": true
}'
Response:
{
"html": "<!DOCTYPE html>\n<html>\n <head></head>\n <body>\n <div>Welcome!</div>\n </body>\n</html>"
}
With Plain Text
Generate both HTML and plain text versions:
curl -X POST http://localhost:3000/api/emails/render \
-H "Content-Type: application/json" \
-d '{
"name": "WelcomeEmail",
"plainText": true,
"props": {
"userName": "John Doe"
}
}'
Response:
{
"html": "<html><head></head><body><div>Welcome John Doe!</div></body></html>",
"text": "Welcome John Doe!"
}
Custom HTML-to-Text Options
Control how HTML is converted to plain text using the html-to-text
options
Related Endpoints
GET /api/emails
- Get all available email templatesPOST /api/emails/source
- Get email template source code