Vue Email

0.8.11 · active · verified Sun Apr 19

Vue Email is a JavaScript library designed for crafting email templates using Vue components. While the current stable release is v0.8.11, the project recently underwent a significant rewrite with v1.0.0, aiming for simpler integration where standard Vue components can be used out-of-the-box. The library provides a comprehensive set of email-specific components (e.g., `EHtml`, `EButton`, `ETailwind`) that abstract away the complexities of cross-client email compatibility. Key differentiators include full SSR support (with a dedicated compiler for Node.js, Deno, and Bun), i18n capabilities, integrations with various email providers like Nodemailer, extensive testing against popular email clients, first-class support for Tailwind CSS, and robust TypeScript typing. The project is under active development, with frequent updates, though it's still noted as experimental, and APIs are subject to change. It integrates particularly well with the Nuxt.js ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to define a simple email template using Vue Email components and programmatically render it to HTML and plain text using the `@vue-email/compiler`.

import { render } from '@vue-email/compiler';
import { defineComponent, h } from 'vue';
import { EHtml, EHead, EBody, EContainer, EText, EButton } from 'vue-email';

// Define your email template as a standard Vue component using Vue Email's components
const WelcomeEmail = defineComponent({
  setup() {
    return () =>
      h(EHtml, { lang: 'en' }, [
        h(EHead),
        h(EBody, [
          h(EContainer, {
            style: 'border: 1px solid #ddd; padding: 20px; border-radius: 8px;'
          }, [
            h(EText, { style: 'font-size: 16px; margin-bottom: 20px;' }, 'Hello from Vue Email!'),
            h(EButton, {
              href: 'https://vuemail.net',
              style: 'background-color: #007bff; color: white; padding: 10px 20px; border-radius: 5px; text-decoration: none;'
            }, 'Visit Vue Email Docs')
          ])
        ])
      ]);
  }
});

async function main() {
  try {
    // Render the Vue component to HTML and plain text
    const { html, text } = await render(WelcomeEmail);
    console.log('Generated HTML Output:\n', html);
    console.log('\nGenerated Plain Text Output:\n', text);
  } catch (error) {
    console.error('Failed to render email:', error);
  }
}

main();

view raw JSON →