GitHub 37
Skip to content
ViteHub is still experimental. Expect bugs and breaking changes.

Email

Send email from your server through Resend or Cloudflare, and write messages as Markdown or Vue templates.

server/api/welcome.post.tsSame on every host
import { defineEventHandler } from 'h3'
import { email } from 'vite-hub/email'

export default defineEventHandler(async () => {
  // Render server/emails/welcome.md. TypeScript checks `data` against the template.
  const [error, sent] = await email.send({
    template: 'welcome',
    data: { user: { name: 'Ada' } },
    from: '[email protected]',
    to: '[email protected]',
  })
  if (error) throw error
  return sent
})
server/api/welcome.post.ts
Deploy on

Node / Docker: Resend / SMTP / custom, set with email.driver

Pick a provider in one place

Choose Resend or Cloudflare Email in your Vite config. Your routes stay the same.

Keys stay out of your code

The server reads your API key from an environment variable when it sends.

Write emails in Markdown or Vue

Files in server/emails become typed templates. email.send({ template, data }) renders HTML and text.

See each email while you develop

In vite dev, each email stays in an outbox. remote: true also sends it through the provider.

Test without sending

createTestEmail() keeps messages in memory for your tests to check.

Clear errors, no double sends

Each failure has an EMAIL_* code. Email does not retry, so nothing sends twice by mistake.