Skip to content

React Email

React Email lets you write email templates as React components. The Node SDK renders them for you through its optional peer dependency @react-email/render.

  1. Install the packages.

    Terminal window
    npm install @spacepost/node @react-email/components @react-email/render react react-dom
  2. Write a template.

    emails/welcome.tsx
    import { Html, Head, Body, Container, Heading, Text, Button, Preview } from "@react-email/components";
    export default function WelcomeEmail({ name, url }: { name: string; url: string }) {
    return (
    <Html>
    <Head />
    <Preview>Welcome to Acme</Preview>
    <Body style={{ backgroundColor: "#f6f9fc", fontFamily: "system-ui, sans-serif" }}>
    <Container style={{ backgroundColor: "#fff", padding: 32, borderRadius: 8 }}>
    <Heading>Welcome, {name}</Heading>
    <Text>Your account is ready.</Text>
    <Button href={url} style={{ background: "#0e9f7a", color: "#fff", padding: "10px 20px", borderRadius: 6 }}>
    Open dashboard
    </Button>
    </Container>
    </Body>
    </Html>
    );
    }
  3. Send it with the react option.

    send.tsx
    import { SpacePost } from "@spacepost/node";
    import WelcomeEmail from "./emails/welcome";
    const spacepost = new SpacePost(process.env.SPACEPOST_API_KEY);
    const { data, error } = await spacepost.emails.send({
    from: "Acme <hello@acme.com>",
    to: "user@example.com",
    subject: "Welcome to Acme",
    react: <WelcomeEmail name="Ada" url="https://app.acme.com" />,
    });

The SDK renders HTML and a plain-text version. If you also pass html or text, yours wins for that field.

With the Resend SDK pointed at SpacePost (see Migrating), the react option works as it does with Resend, because the SDK renders before sending.