Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

React Email

Write an email as React components in your own project, render it to HTML and use that HTML as a BillionSend template or send it directly.

BillionSend takes HTML. If you write emails with React Email, you render them in your own project and send or upload the HTML. BillionSend never runs your code, so there is nothing to install on our side.

Send a rendered email

import { render } from "@react-email/render";
import { BillionSend } from "@billionsend/node";
import { Welcome } from "./emails/welcome";

const bs = new BillionSend(); // reads BILLIONSEND_API_KEY

const html = await render(<Welcome name="Ada" />);
const text = await render(<Welcome name="Ada" />, { plainText: true });

await bs.emails.send({
  from: "Acme <hello@mail.example.com>",
  to: "ada@example.com",
  subject: "Welcome to Acme",
  html,
  text,
});

Preview text written with React Email’s Preview component is rendered into the HTML as a hidden preheader, so it travels with the email.

Keep it as a template

To edit the email or send it by id later, create a template from the rendered HTML:

await bs.templates.create({
  name: "Welcome",
  subject: "Welcome to {{{FIRST_NAME|there}}}",
  html: await render(<Welcome name="{{{FIRST_NAME|there}}}" />),
});

Pass merge fields as strings, so the rendered HTML carries {{{NAME}}} or {{{NAME|fallback}}} for BillionSend to fill in for each contact. The template is an HTML template: the dashboard opens it in code mode with a live preview, where you can also use Import HTML to load a file you rendered, up to 1 MB. The file is read in your browser and nothing is saved until you save the template.

Include {{{UNSUBSCRIBE_URL}}} in broadcast content, or BillionSend adds a default unsubscribe link for you. See Unsubscribes.

What is not done

BillionSend does not accept .tsx source and does not render React on its servers: running your code would mean running it with your dependencies and your secrets, which is better left in your own build. To rebuild an HTML template as blocks for the block editor, use Convert to blocks in the dashboard; it keeps your text and drops layout the blocks cannot express. To change wording or tone on a template’s blocks, use the AI editor.

Was this page helpful?