INTEGRATIONS · PAYMENTS AND COMMERCE
Send a receipt email when a Razorpay payment succeeds
Razorpay tells your server the moment a payment is captured. Verify the webhook, then send your own branded receipt from your domain, with the amount in rupees and the payment ID your customer can quote.
- 3,000 emails a month free
- Billed in INR
- Sent from Mumbai
import crypto from "node:crypto";
export async function POST(request: Request) {
const body = await request.text();
const signature = request.headers.get("x-razorpay-signature") ?? "";
const expected = crypto
.createHmac("sha256", process.env.RAZORPAY_WEBHOOK_SECRET!)
.update(body)
.digest("hex");
if (signature.length !== expected.length ||
!crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))) {
return new Response("Invalid signature", { status: 400 });
}
const event = JSON.parse(body);
if (event.event !== "payment.captured") return new Response("ignored");
…HOW IT WORKS
Live in three steps.
- 01
Verify your domain
Add the DNS records MailKaka shows you. Usually a few minutes.
- 02
Create an API key
Keep it in a server-side secret called MAILKAKA_API_KEY.
- 03
Send from a webhook
Verify Razorpay's signature, then send one request.
CODE
Handle the payment.captured webhook
In the Razorpay Dashboard, add a webhook pointing at this route, choose the payment.captured event and set a secret. Store it as RAZORPAY_WEBHOOK_SECRET.
- 1Create a free MailKaka account. The free plan includes 3,000 emails a month.
- 2Add your domain in the dashboard and copy the DNS records it shows, including the _mailkaka-verify TXT record, to your DNS provider. Sending works once the domain shows Verified.
- 3Create an API key for that domain. It starts with mk_. Store it as a secret called MAILKAKA_API_KEY, never in frontend code.
- 4In Razorpay, open Accounts & Settings → Webhooks, add your route's URL, tick payment.captured, and set a webhook secret.
- 5Deploy the route below. Test it with a test-mode payment before switching to live keys.
import crypto from "node:crypto";
export async function POST(request: Request) {
const body = await request.text();
const signature = request.headers.get("x-razorpay-signature") ?? "";
const expected = crypto
.createHmac("sha256", process.env.RAZORPAY_WEBHOOK_SECRET!)
.update(body)
.digest("hex");
if (signature.length !== expected.length ||
!crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))) {
return new Response("Invalid signature", { status: 400 });
}
const event = JSON.parse(body);
if (event.event !== "payment.captured") return new Response("ignored");
const payment = event.payload.payment.entity;
const rupees = (payment.amount / 100).toLocaleString("en-IN", { style: "currency", currency: "INR" });
const res = await fetch("https://www.mailkaka.in/api/emails", {
method: "POST",
headers: {
Authorization: "Bearer " + process.env.MAILKAKA_API_KEY,
"Content-Type": "application/json",
"Idempotency-Key": "receipt-" + payment.id,
},
body: JSON.stringify({
from: "Acme Payments <billing@yourdomain.com>",
to: [payment.email],
subject: "Payment received: " + rupees,
html: "<p>We received " + rupees + ". Payment ID: " + payment.id + "</p>",
}),
});
if (!res.ok) return new Response("Email failed", { status: 500 });
return new Response("ok");
}- Razorpay retries a webhook that doesn't get a 2xx response. The Idempotency-Key header means a retry can't email the customer twice.
- Read the raw body before parsing it. The signature is computed over the exact bytes Razorpay sent.
WHAT YOU CAN SEND
Every email your app needs.
Welcome emails
Greet every new sign-up from your own address.
OTPs and password resets
Sign-in codes and reset links that arrive fast.
Orders and receipts
Confirmations, invoices and shipping updates.
Replies that reach you
Customer replies land in a shared team mailbox.
BUILT FOR AI AGENTS
Let Claude Code, Cursor or any MCP client run your email.
MailKaka hosts an MCP server. Connect your coding agent once, and it can add your domain and show the DNS records, check verification, send a test email, read delivery status, and create the API key your app needs. You sign in from a browser and choose what it's allowed to do.
- Per-agent limits: 60 sends a minute and 500 emails a day
- Separate permissions for viewing, changing, sending and mailboxes
- A preview before deletes, batch sends and new API keys
- Every connection listed, and removable, in the dashboard
claude mcp add --transport http mailkaka https://www.mailkaka.in/api/mcpFAQ
Common questions.
Doesn't Razorpay already email the customer?
Razorpay can send its own payment emails, with Razorpay's branding. Your own receipt comes from your domain, matches your product, and can include order details Razorpay doesn't know.
Can I also email on failed payments or refunds?
Yes. Subscribe to payment.failed or refund.processed in the same webhook and send a different email for each event.
Does MailKaka have an SDK for this language?
You don't need one: sending is a single HTTPS POST with a JSON body, as shown above. If your code already uses Resend's Node SDK, you can keep it and point it at MailKaka instead.
Can I use SMTP instead?
SMTP is not switched on by default, so the HTTP API is the way to send. It is also faster to set up, and every send shows up in your dashboard's logs.
Is MailKaka a good email API for Indian startups?
It's built for them. Email is sent from Mumbai, plans are priced and billed in INR through Razorpay (UPI and cards), and the free plan covers 3,000 emails a month. It accepts the same send request as Resend, so moving later is easy either way.
START WITH ONE DOMAIN
Send your first email from Razorpay today.
Free for 3,000 emails a month. Paid plans are billed in INR through Razorpay.
RELATED