How to Send React Email Templates with Mailofly
Design responsive, bulletproof transactional email templates using React, Tailwind CSS, and TypeScript. Render to HTML on the fly and deliver via Mailofly REST API.
npm install @mailofly/node @react-email/components @react-email/renderGet Up and Running in 3 Easy Steps
Install dependencies
Install `@mailofly/node` along with `@react-email/components` and `@react-email/render` in your project.
Create your React Email component
Author responsive JSX templates using React Email primitives like `<Container>`, `<Text>`, and Tailwind CSS styling.
Render and send with Mailofly
Call `render(<Template />)` server-side to generate HTML, then pass it directly into `mailofly.emails.send({ html })`.
Production-Ready Code Example
Copy and paste into your project. Fully typed and tested.
import { Mailofly } from "@mailofly/node";
import { render } from "@react-email/render";
import { WelcomeEmail } from "@/emails/welcome";
import { NextResponse } from "next/server";
const mailofly = new Mailofly({
apiKey: process.env.MAILOFLY_API_KEY!,
});
export async function POST(request: Request) {
try {
const { email, name } = await request.json();
// 1. Render React Email component to static HTML
const emailHtml = await render(
WelcomeEmail({ name, loginUrl: "https://yourdomain.com/login" })
);
// 2. Dispatch via Mailofly REST API
const data = await mailofly.emails.send({
from: "Acme App <notifications@yourdomain.com>",
to: [email],
subject: `Welcome to Acme, ${name}!`,
html: emailHtml,
tags: [{ name: "template", value: "welcome-react" }],
});
return NextResponse.json({ success: true, messageId: data.id });
} catch (error: any) {
return NextResponse.json({ error: error.message }, { status: 500 });
}
}Engineered for React Email
Declarative JSX Email Architecture
Say goodbye to complex nested tables. Build maintainable, modular components with standard React patterns.
Zero Serverless Socket Timeouts
Because Mailofly uses HTTP REST API, rendering and sending in Vercel or AWS Lambda completes in milliseconds without SMTP connection drops.
Type-Safe Template Props
Catch missing variables and typo bugs at build time with full TypeScript type safety across your email components.
Explore Mailofly Infrastructure Capabilities
Build resilient, high-deliverability email systems with our core developer tools.
Frequently Asked Questions about React Email
Start Sending from React Email in Minutes
3,000 free emails every month. Copy your API key, run the code snippet, and watch your delivery logs in real time.
