Overview
ThecreateEmail() function returns a SvelteKit form action that renders email components to HTML. Use this with the EmailPreview component to preview your email templates in the browser.
Function Signature
Parameters
Optional configuration object
Custom renderer instance with your Tailwind config. If not provided, uses default renderer
Return Type
SvelteKit actions object to be exported from
+page.server.tsUsage
Basic Example
+page.server.ts
With Custom Renderer
Use a custom renderer to apply your own Tailwind configuration:+page.server.ts
Complete Setup with EmailPreview
+page.server.ts
+page.svelte
The
EmailPreview component automatically calls the create-email action when you select an email template from the list.How It Works
- The
EmailPreviewcomponent submits a form withfileandpathparameters - The
create-emailaction receives the form data - The email component is dynamically imported from your project
- The component is rendered to HTML using the provided renderer
- The HTML is formatted with Prettier for readability
- Both the rendered HTML and source code are returned to the client
Error Handling
Missing Parameters (400)
Iffile or path parameters are missing from the form data:
Render Error (500)
If the email component fails to import or render:Performance Considerations
- Email components are dynamically imported on each request
- The renderer processes Tailwind CSS classes and inlines styles
- Prettier formats the output HTML (adds ~50-100ms)
- Consider caching rendered emails in production if performance is critical
Related Functions
- emailList() - Get list of available email components
- sendEmail() - Send rendered emails via Resend
- Renderer - Learn more about custom Tailwind configuration