server side rendering

Node And Bun

Server-Side Rendering with Node and Bun

The bun support is available on version `0.8.0-beta' and above

Introduction

Vue Email can now be used to render and send emails from the server side, and now with support for bun. This is useful for sending transactional emails, such as welcome emails, password resets, and more.

Installation

We already have the compiler features from the vue-email package, but you even can install it without needs to install the vue-email package, and you can do it as such install the @vue-email/compiler package.

Config

The config method takes two arguments, the first is the path to the directory containing the template files, and the second is an optional config object.

KeyDefaultDescription
verbosefalseWhether to log the compilation process to the console.
options{}The options to pass to the compiler. Supported Options
import { config } from "@vue-email/compiler";

const vueEmail = config("./templates", {
  verbose: false,
  options: {
    baseUrl: "https://vue-email-demo.vercel.app/",
  },
});

Render

The render method takes two arguments, the first is the name of the template file, and the second is an optional props object.

const template = await vueEmail.render("DefineComponent.vue", {
  props: {
    name: "John Doe",
  },
});

Example

in this example we will use Express.js to render and view an email.

Express.js
import express from "express";
import { config } from "@vue-email/compiler";

const app = express();

const vueEmail = config("./templates", {
  verbose: false,
  options: {
    baseUrl: "https://vue-email-demo.vercel.app/",
  },
});

app.get("/", async function (req, res) {
  const template = await vueEmail.render("WelcomeEmail.vue", {
    props: {
      name: "John Doe",
    },
  });
  res.send(template);
});

app.listen(3000);

Sending Emails

Once you have rendered your email template, you can send it using any email provider you like.

Vue Email does not provide any email sending functionality, you will need to use a third party email provider to send your emails, check the integration section for more information. Integrations

Bugs and Issues

If you encounter any bugs or issues, feel free to open an issue at GitHub