Use Case
Send OTP code emails with Postkit
Deliver one-time passcodes for two-factor authentication. Postkit's fast delivery ensures the code arrives before it expires.
Get Started FreeThe problem
OTP codes have a short window — typically 60 to 300 seconds. If delivery takes longer than that, the user is locked out. Duplicate sends waste codes and confuse users.
The Postkit solution
Postkit delivers in under a second. Use an idempotency key per OTP attempt so retries don't generate multiple emails. Keep the email body minimal for instant rendering.
send-otp.ts
await fetch("https://api.postkit.eu/v1/emails", {
method: "POST",
headers: {
Authorization: "Bearer pk_live_...",
"Content-Type": "application/json",
"Idempotency-Key": `otp-${otpId}`,
},
body: JSON.stringify({
from: "security@yourapp.eu",
to: user.email,
subject: `Your code: ${otpCode}`,
html: `<p>Your verification code is: <strong>${otpCode}</strong></p>
<p>It expires in 5 minutes.</p>`,
}),
});