Prompt
How do I send transactional emails from an API?
Latest observation
Jul 24, 2026 · OpenAI APIWeb search: off
To send transactional emails from an API, you typically use an email delivery service (like SendGrid, Mailgun, Amazon SES, Postmark, etc.) and call their API from your backend whenever an event happens, such as:
- user signs up
- password reset requested
- order confirmation
- receipt/invoice generated
- shipping update
Basic flow
- Choose an email provider
- Verify your sending domain
- Create API credentials
- Build an email template
- Call the provider’s API from your app
- Handle responses, retries, and errors
Example API request
Here’s a generic example using JSON:
curl -X POST https://api.emailprovider.com/v1/send \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"from": "Acme <no-reply@acme.com>",
"to": "user@example.com",
"subject": "Reset your password",
"html": "<p>Click <a href=\"https://example.com/reset?token=abc\">here</a> to reset your password.</p>"
}'
Example in Node.js
const response = await fetch('https://api.emailprovider.com/v1/send', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.EMAIL_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
from: 'Acme <no-reply@acme.com>',
to: 'user@example.com',
subject: 'Welcome!',
text: 'Thanks for signing up.'
})
});
const data = await response.json();
console.log(data);
Best practices
- Send from your backend, not directly from frontend code
- Use a verified sending domain to improve deliverability
- Include both HTML and plain-text versions
- Use template variables for personalization
- Make requests idempotent if possible to avoid duplicate emails
- Add logging and monitoring
- Respect unsubscribe requirements where applicable
- Protect API keys using environment variables or secrets managers
What makes an email transactional?
Transactional emails are triggered by a user action or account event and are usually:
- expected by the user
- time-sensitive
- not marketing/promotional
Examples:
- password reset
- email verification
- account notification
- payment receipt
If you want, I can also show you:
- a real example using SendGrid, Mailgun, SES, or Postmark
- how to do this in Python / Node.js / Ruby / Go
- how to set up templates and webhooks for delivery tracking