Prompt
How do I send personalized receipts and onboarding emails using event payload data?
Latest observation
Nov 24, 2026
OpenAI APIWeb search: off
You can do this by treating each event payload as the source of truth for personalization, then mapping its fields into your email templates.
1) Include the right data in the event payload
When your backend emits an event like payment.succeeded or user.created, include the fields you’ll need for the email:
- recipient name
- email address
- order / invoice / plan details
- company name
- onboarding step or product usage info
- links you want to include
- locale / timezone if relevant
Example payload:
{
"event_type": "payment.succeeded",
"user": {
"id": "usr_123",
"name": "Ava Chen",
"email": "ava@example.com"
},
"receipt": {
"receipt_number": "R-10021",
"amount": 49.00,
"currency": "USD",
"paid_at": "2026-11-24T10:30:00Z",
"items": [
{ "name": "Pro Plan", "quantity": 1, "price": 49.00 }
]
},
"account": {
"company_name": "Acme Co"
}
}
2) Create templates with variables
Use placeholders in your email template that match the payload fields.
Receipt template example
<h1>Thanks, {{user.name}}!</h1>
<p>Your payment for {{account.company_name}} was successful.</p>
<p>Receipt #{{receipt.receipt_number}}</p>
<p>Amount: {{receipt.amount}} {{receipt.currency}}</p>
<ul>
{{#each receipt.items}}
<li>{{name}} x{{quantity}} — {{price}}</li>
{{/each}}
</ul>
Onboarding template example
<h1>Welcome, {{user.name}}!</h1>
<p>We’re excited to have you at {{account.company_name}}.</p>
<p>Next step: {{onboarding.next_step}}</p>
<p><a href="{{onboarding.dashboard_url}}">Go to dashboard</a></p>
3) Render the template when the event arrives
Your app or email provider receives the event, merges payload data into the template, and sends the email.
Pseudo-code:
function handleEvent(event) {
const template =
event.event_type === "payment.succeeded"
? "receipt-template"
: "onboarding-template";
const html = renderTemplate(template, event);
sendEmail({
to: event.user.email,
subject:
event.event_type === "payment.succeeded"
? `Your receipt from ${event.account.company_name}`
: `Welcome to ${event.account.company_name}`,
html
});
}
4) Use conditional logic for personalization
You can change copy based on event data:
- show different plans or tiers
- localize currency/date format
- add a CTA only if a URL exists
- include discount details only when present
Example:
{{#if receipt.discount}}
<p>Discount applied: {{receipt.discount}}</p>
{{/if}}
5) Make sure the payload is safe and complete
Best practices:
- validate required fields before sending
- escape user-generated content to prevent HTML injection
- keep templates versioned
- store a copy of the payload used for each sent email
- test with sample payloads
6) Typical flow
- User action happens in your app
- Backend emits event payload
- Event is received by your email service
- Template is selected based on event type
- Payload values are merged into template
- Personalized email is sent
If you want, I can also show:
- a Node.js example
- a Python example
- a Mailchimp/SendGrid/Customer.io setup
- a receipts + onboarding payload schema