Send Transactional Email from Remix (React Router v7)
Pranav Patel
Co-founder·10 min read
On this page

Send transactional email from Remix and React Router v7 with Reloop: a server-only client, route actions, Form and useFetcher, React Email templates, error handling, webhooks and deployment.
In Remix, send email from a route action. Actions run only on the server, so your API key never reaches the browser. Create one Reloop client in a .server.ts module, call reloop.mail.send() inside the action, and return a small result the page can show. That's the whole pattern.
A note on names: Remix v2 and React Router v7 are now the same framework. React Router v7's "framework mode" is what Remix v3 would have been, and the Remix team recommends it for new apps. This guide uses React Router v7 code, and points out the one or two places where Remix v2 differs.
Using a different framework? See the guides for Next.js, SvelteKit or plain Node.js.
What you'll build
app/lib/reloop.server.tsapp/routes/signup.tsxapp/routes/api.reloop-webhook.tsapp/emails/welcome.tsxPrerequisites
- A React Router v7 app (
npx create-react-router@latest) or a Remix v2 app. - A Reloop API key from the dashboard. Keys start with
rl_. - A verified sending domain. See connect a domain.
1. Install the SDK
npm install reloop-emailThe package is reloop-email. It has no runtime dependencies besides fetch, which every supported Node version has.
2. Add your API key
In .env at the project root:
RELOOP_API_KEY=rl_your_api_key_hereDon't rely on the framework to load .env into process.env for you. Load it explicitly in development, either with dotenv (import "dotenv/config" at the top of your server entry) or Node's built-in --env-file=.env flag. In production, set RELOOP_API_KEY in your host's environment settings (Fly, Render, Railway, a VPS's systemd unit, and so on).
3. Create a server-only client
The .server.ts suffix tells the bundler this module must never end up in client code. If you import it from a component by mistake, the build fails instead of leaking your key.
1import { Reloop } from "reloop-email";2
3const apiKey = process.env.RELOOP_API_KEY;4
5if (!apiKey) {6 throw new Error("Missing RELOOP_API_KEY");7}8
9export const reloop = new Reloop({ apiKey });If you self-host Reloop, pass baseUrl: "https://reloop.example.com" as well.
4. Send from a route action
Here's a signup route. The action validates the email, creates the user, and sends a welcome email.
1import { data, Form, useActionData, useNavigation } from "react-router";2import { reloop } from "~/lib/reloop.server";3import type { Route } from "./+types/signup";4
5export async function action({ request }: Route.ActionArgs) {6 const formData = await request.formData();7 const email = String(formData.get("email") ?? "").trim().toLowerCase();8 const name = String(formData.get("name") ?? "").trim();9
10 if (!email.includes("@")) {11 return data({ ok: false, error: "Enter a valid email address." }, { status: 400 });12 }13
14 const user = await createUser({ email, name });15
16 const { response, emailError } = await reloop.mail.send({17 from: "Acme <hello@mail.acme.com>",18 to: user.email,19 subject: name ? `Welcome to Acme, ${name}` : "Welcome to Acme",20 html: `<p>Hi ${name || "there"},</p><p>Your account is ready.</p>`,21 text: `Hi ${name || "there"}, your account is ready.`,22 reply_to: "support@acme.com",23 tags: [{ name: "type", value: "welcome" }],24 });25
26 if (emailError) {27 // The account exists; don't fail signup because of email.28 console.error("Welcome email failed", emailError.status, emailError.message);29 }30
31 return { ok: true, emailId: response?.id ?? null };32}33
34export default function Signup() {35 const actionData = useActionData<typeof action>();36 const navigation = useNavigation();37 const submitting = navigation.state === "submitting";38
39 return (40 <Form method="post" className="space-y-3">41 <input name="name" placeholder="Name" />42 <input name="email" type="email" required placeholder="you@company.com" />43 <button type="submit" disabled={submitting}>44 {submitting ? "Creating account…" : "Create account"}45 </button>46 {actionData && !actionData.ok ? <p>{actionData.error}</p> : null}47 {actionData?.ok ? <p>Check your inbox.</p> : null}48 </Form>49 );50}A few things worth noticing:
- The SDK doesn't throw on API errors. It returns
{ response, emailError }.emailErrorhas the HTTPstatus, amessage, and the full errorbodywith Reloop'scode,whyandfixfields. data()sets the status code while still returning JSON. In Remix v2, usejson()from@remix-run/nodeinstead.- The form works without JavaScript.
<Form method="post">posts to the action; React Router upgrades it to a fetch when JS is loaded. - Types come for free.
Route.ActionArgsis generated by React Router's type generation. In Remix v2, useActionFunctionArgsfrom@remix-run/node.
5. Send without navigating: useFetcher
For things like "resend verification email" buttons, you don't want a page transition. useFetcher calls the action in the background:
1import { useFetcher } from "react-router";2import { reloop } from "~/lib/reloop.server";3import type { Route } from "./+types/settings";4
5export async function action({ request }: Route.ActionArgs) {6 const user = await requireUser(request);7
8 const { emailError } = await reloop.mail.send({9 from: "Acme <hello@mail.acme.com>",10 to: user.email,11 subject: "Verify your email",12 html: `<p><a href="${verifyUrl(user)}">Verify your email</a></p>`,13 text: `Verify your email: ${verifyUrl(user)}`,14 });15
16 return { sent: !emailError };17}18
19export default function Settings() {20 const fetcher = useFetcher<typeof action>();21
22 return (23 <fetcher.Form method="post">24 <button type="submit" disabled={fetcher.state !== "idle"}>25 {fetcher.state !== "idle" ? "Sending…" : "Resend verification email"}26 </button>27 {fetcher.data?.sent ? <span>Sent. Check your inbox.</span> : null}28 </fetcher.Form>29 );30}Always authenticate inside the action (requireUser here). An action is a public HTTP endpoint, and an unauthenticated send endpoint can be abused to spam people from your domain.
6. Use React Email templates
Inline HTML strings get messy fast. The Reloop SDK accepts a react field and renders it to HTML for you, using @react-email/render if it's installed or react-dom/server otherwise.
npm install @react-email/components @react-email/render1import { Body, Button, Container, Heading, Html, Text } from "@react-email/components";2
3export function WelcomeEmail({ name, url }: { name: string; url: string }) {4 return (5 <Html>6 <Body style={{ fontFamily: "Inter, Arial, sans-serif" }}>7 <Container>8 <Heading>Welcome, {name}</Heading>9 <Text>Your account is ready. Start with your first project.</Text>10 <Button href={url}>Open dashboard</Button>11 </Container>12 </Body>13 </Html>14 );15}1import { WelcomeEmail } from "~/emails/welcome";2
3await reloop.mail.send({4 from: "Acme <hello@mail.acme.com>",5 to: user.email,6 subject: "Welcome to Acme",7 react: <WelcomeEmail name={user.name} url="https://app.acme.com" />,8});Keep email components in a server-only folder and import them only from actions or .server.ts files.
Prefer to edit templates without a deploy? Create the template in the Reloop dashboard and send it by ID with variables:
1await reloop.mail.send({2 from: "Acme <hello@mail.acme.com>",3 to: user.email,4 subject: "Reset your password",5 template: {6 id: "tmpl_password_reset",7 variables: { name: user.name, reset_url: resetUrl },8 },9});7. Receive delivery events with a resource route
A route with an action and no default export is a resource route: a plain HTTP endpoint. That's the right place for Reloop webhooks (bounces, complaints, deliveries).
1import { createHmac, timingSafeEqual } from "node:crypto";2import type { Route } from "./+types/api.reloop-webhook";3
4function verify(rawBody: string, header: string, secret: string) {5 const parts = Object.fromEntries(6 header.split(",").map((p) => p.trim().split("=") as [string, string]),7 );8 const timestamp = Number(parts.t);9 if (!parts.v1 || Math.abs(Date.now() / 1000 - timestamp) > 300) return false;10
11 const expected = createHmac("sha256", secret)12 .update(`${timestamp}.${rawBody}`)13 .digest("hex");14 const a = Buffer.from(expected, "hex");15 const b = Buffer.from(parts.v1, "hex");16 return a.length === b.length && timingSafeEqual(a, b);17}18
19export async function action({ request }: Route.ActionArgs) {20 const rawBody = await request.text();21 const signature = request.headers.get("Reloop-Signature") ?? "";22
23 if (!verify(rawBody, signature, process.env.RELOOP_WEBHOOK_SECRET!)) {24 return new Response("Invalid signature", { status: 401 });25 }26
27 const event = JSON.parse(rawBody) as {28 type: string;29 data: { email_id: string; to: string[] };30 };31
32 if (event.type === "email.bounced" || event.type === "email.complained") {33 await markEmailUndeliverable(event.data.to[0]);34 }35
36 return new Response("ok");37}Read the body with request.text() before parsing: the signature is computed over the raw bytes. The full algorithm and the list of event types are in the docs on verifying webhooks and event types.
8. Handle errors and retries
emailError.status is 4xxemailError.status is 429emailError.status is 5xx or 0Idempotency-Key header, or a job queue that tracks sends.For high-value sends like receipts, don't send inside the request at all. Put a job on a queue (BullMQ, pg-boss, your host's queue) and send from a worker, so a slow or failed send never affects the user's request.
9. Deploy
React Router v7 apps run anywhere Node runs, and on edge platforms with the right adapter.
RELOOP_API_KEY.env loaded by your process managerfly secrets set RELOOP_API_KEY=rl_…wrangler secret put RELOOP_API_KEY, then read it from the request contextOn Cloudflare, the SDK needs the nodejs_compat flag. See sending email from Cloudflare Workers for the details and a dependency-free fetch version.
FAQ
You can, but you shouldn't. Loaders run on GET requests, which can be prefetched, retried and cached. Sending email is a side effect, so it belongs in an action.
The Reloop code is identical. The differences are imports: Remix v2 uses
@remix-run/node for json and ActionFunctionArgs, React Router v7
uses data from react-router and generated Route types.
Send to your own address from a verified domain, then inspect the message, its headers and delivery status in the Reloop dashboard logs.
Ship your first email with Reloop
in minutes.
Open-source, deliverability-focused, and yours to self-host or run on Reloop Cloud. No lock-in, no rewrite later.


