Prompt
How do I send receipt emails from my backend?
Latest observation
Nov 25, 2026
OpenAI APIWeb search: off
To send receipt emails from your backend, the usual flow is:
- Detect a completed purchase/payment
- Generate receipt content
- Send an email through an email service
- Log/store the receipt for later lookup
Typical setup
1) Use an email provider
Don’t send mail directly from your app server if you can avoid it. Use a provider like:
- SendGrid
- Mailgun
- AWS SES
- Postmark
- Resend
These handle deliverability, retries, SPF/DKIM, etc.
2) Trigger on payment success
If you use Stripe, PayPal, or another processor, listen for a webhook event like:
payment_intent.succeededcheckout.session.completedcharge.succeeded
When the webhook arrives, verify it and then create/send the receipt email.
3) Build the receipt
Include:
- Order ID
- Date/time
- Items purchased
- Subtotal, tax, discounts, total
- Payment method summary
- Support contact
- Refund policy link
- Receipt/invoice number
4) Send the email
Usually via an API call to your provider.
Example in Node.js using Nodemailer with SMTP:
import nodemailer from "nodemailer";
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: 587,
secure: false,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS,
},
});
async function sendReceiptEmail({ to, orderId, total }) {
await transporter.sendMail({
from: '"Your Store" <receipts@yourstore.com>',
to,
subject: `Receipt for Order ${orderId}`,
html: `
<h1>Thanks for your purchase</h1>
<p>Order ID: ${orderId}</p>
<p>Total: $${total}</p>
`,
});
}
Best practices
- Send asynchronously using a queue/background job so your webhook returns quickly.
- Verify webhooks to prevent fake receipt sending.
- Make it idempotent so the same payment event doesn’t send duplicate receipts.
- Store receipt records in your DB.
- Use a templating system for professional-looking emails.
- Handle failures with retries and dead-letter logging.
If you use Stripe
You can also let Stripe send customer receipts automatically for some payment flows, but if you want custom branding/content, backend email sending is better.
Recommended architecture
- Payment provider webhook → backend endpoint
- Backend verifies event
- Backend writes order/receipt to DB
- Backend enqueues email job
- Worker sends email via provider API
If you want, I can give you a complete example in Node.js, Python, or Go, including webhook handling and email sending.