Skip to main content

renderEmail

Renders a Svelte component to an HTML email string.

Signature

function renderEmail<
Comp extends Component<any>,
Props extends ComponentProps<Comp>,
>(component: Comp, props: Props): string

How it works

  1. Renders the Svelte component to an MJML string using svelte/server
  2. Converts the MJML markup to responsive HTML using mjml2html
  3. Returns the final HTML string

Usage

import { renderEmail } from '@repo/notifications'
import WelcomeEmail from '$lib/emails/Welcome.svelte'

const html = renderEmail(WelcomeEmail, {
username: 'Jane',
activationUrl: 'https://example.com/activate/abc123'
})

The returned html is a complete, self-contained HTML document ready for any email transport.