Quickstart
Install the package, write an email in React, and send it.
Write your email as a React component, turn it into HTML with render(), and send it with any provider. The HTML works in Outlook, Gmail, and Apple Mail. You don't need a Unitpost account.
1. Install
npm install @unitpost/email zodReact and Next.js apps already have react. In a plain Node project, install it too. zod is a peer dependency. Node 18 or newer.
Or let init set the project up: it adds a starter email to emails/ and an email:dev script to package.json, then prints the install command for anything missing. It keeps files and scripts that are already there.
npx @unitpost/email init2. Create an email
An email is a React component made of the library's components. Pass data in as props, like any other component.
import { Section, Heading, Text, Button } from "@unitpost/email/react";
export function WelcomeEmail({ name }: { name: string }) {
return (
<Section>
<Heading>Welcome, {name}</Heading>
<Text>Thanks for signing up. Confirm your email to get started.</Text>
<Button href="https://example.com/confirm">Confirm email</Button>
</Section>
);
}3. Render and send
render() returns an HTML string. Send it with the Unitpost SDK, or with the provider you already use (see Integrations).
import { render } from "@unitpost/email/react";
import { Unitpost } from "unitpost";
import { WelcomeEmail } from "./emails/welcome";
const unitpost = new Unitpost(process.env.UNITPOST_API_KEY);
await unitpost.email.send({
from: "Acme <hello@acme.com>",
to: "ada@example.com",
subject: "Welcome to Acme",
html: render(<WelcomeEmail name="Ada" />),
});4. Preview while you build
Run the preview server next to your app. It lists every email in emails/, reloads when a file changes, and shows the email at desktop and mobile width, in light and dark, with its HTML, plain text and design checks. Preview props come from Welcome.PreviewProps. It bundles your emails with esbuild, so add it once: npm install -D esbuild. After init, npm run email:dev starts the same server.
npx @unitpost/email devTo see an email in a real inbox, set UNITPOST_API_KEY and UNITPOST_FROM and use Send test.
Using a coding agent?
Run npx skills add unitpostcom/email and your agent learns every component and layout.