Introduction
Next.js 15 brings powerful Server Actions and streaming primitives. In this guide, we'll demonstrate how to send transactional emails (such as welcome emails, password resets, and purchase invoices) directly from a Next.js 15 App Router application with sub-20ms latency.
---
Step 1: Configure Your Environment
Sendport provides a high-speed HTTP REST API compatible with any Node.js, Bun, Edge, or Cloudflare Worker runtime without external dependencies.
Add your API key to `.env.local`:
SENDPORT_API_KEY=sk_live_your_api_key_here
---
Step 2: Create a Server Action
Create a new file at `app/actions/send-welcome.ts`:
"use server";export async function sendWelcomeEmail(toEmail: string, userName: string) {
try {
const res = await fetch("https://api.getsendport.com/v1/emails/send", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.SENDPORT_API_KEY}`,
},
body: JSON.stringify({
from: "Acme App ",
to: toEmail,
subject: `Welcome to Acme, ${userName}!`,
html: `
Welcome aboard, ${userName}!
Thank you for signing up. Your account is now active and ready to go.
Go to Your Dashboard →
`,
}),
}); const data = await res.json();
if (!res.ok) {
throw new Error(data.error || "Failed to dispatch email");
}
return { success: true, messageId: data.messageId };
} catch (error: any) {
return { success: false, error: error.message };
}
}
---
Step 3: Trigger in Your Signup Component
"use client";import { useState } from "react";
import { sendWelcomeEmail } from "@/app/actions/send-welcome";
export function SignupForm() {
const [email, setEmail] = useState("");
const [name, setName] = useState("");
const [status, setStatus] = useState("");
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setStatus("Sending welcome email...");
const result = await sendWelcomeEmail(email, name);
if (result.success) {
setStatus("Email sent! Check your inbox.");
} else {
setStatus("Error: " + result.error);
}
};
return (
);
}
---
Conclusion
With Sendport's global edge network, transactional emails dispatch in under 18ms with automated DKIM signing. You get free open/click tracking and webhook delivery out of the box.