PadiMail Docs
Sending

React Email

Write emails as React components and send them with the Node SDK.

NeedsAny accountTest keys work as soon as you sign up. Nothing is delivered.

React Email lets you build emails from components that render well in every mail client. The Node SDK renders them for you.

Install

npm install @padimail/node @react-email/render @react-email/components

Write a component

emails/receipt.tsx
import { Body, Container, Head, Heading, Html, Preview, Text } from "@react-email/components";

export function ReceiptEmail({ orderNo, total }: { orderNo: string; total: string }) {
  return (
    <Html>
      <Head />
      <Preview>Your receipt for order #{orderNo}</Preview>
      <Body style={{ fontFamily: "sans-serif" }}>
        <Container>
          <Heading>Thanks for your order</Heading>
          <Text>Order #{orderNo} came to {total}.</Text>
        </Container>
      </Body>
    </Html>
  );
}

Send it

import { PadiMail } from "@padimail/node";
import { ReceiptEmail } from "./emails/receipt";

const pm = new PadiMail(process.env.PADIMAIL_API_KEY);

await pm.emails.send({
  from: "Acme Store <hello@acme.ng>",
  to: "ada@example.com",
  subject: "Your receipt #1042",
  react: <ReceiptEmail orderNo="1042" total="₦12,500" />,
});

The SDK renders react to html, and to text unless you pass your own text. You can't combine react with html or template. It works in batches too.

Without the SDK

Render the component yourself and send the HTML:

import { render } from "@react-email/render";

const html = await render(<ReceiptEmail orderNo="1042" total="₦12,500" />);
curl -X POST https://api.padimail.app/v1/emails \
  -H "Authorization: Bearer $PADIMAIL_API_KEY" -H "Content-Type: application/json" \
  -d "{\"from\": \"Acme Store <hello@acme.ng>\", \"to\": \"ada@example.com\", \"subject\": \"Your receipt\", \"html\": $(jq -Rs . < receipt.html)}"
Was this page helpful?

On this page