Prompt
How do I send transactional emails from my app with an API?
Latest observation
Oct 11, 2026
OpenAI APIWeb search: off
To send transactional emails from your app with an API, you typically use an email service provider (ESP) like SendGrid, Mailgun, Postmark, Amazon SES, or Resend.
Basic flow
- Create an account with an email API provider.
- Verify your sending domain so emails aren’t flagged as spam.
- Get an API key from the provider.
- Call the provider’s API from your backend when an event happens, like:
- user signs up
- password reset requested
- receipt/invoice generated
- email verification needed
- Use templates for consistent transactional messages.
- Handle errors and retries in your app.
Example API request
Most providers use a POST request like this:
curl -X POST "https://api.provider.com/send" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"from": "Your App <noreply@yourdomain.com>",
"to": "user@example.com",
"subject": "Reset your password",
"html": "<p>Click here to reset your password.</p>"
}'
Example in Node.js
import fetch from "node-fetch";
async function sendEmail() {
const res = await fetch("https://api.provider.com/send", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.EMAIL_API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
from: "Your App <noreply@yourdomain.com>",
to: "user@example.com",
subject: "Welcome!",
html: "<p>Thanks for signing up.</p>"
})
});
if (!res.ok) {
throw new Error(`Email send failed: ${res.status}`);
}
return await res.json();
}
Good practices
- Send from backend only: never expose API keys in frontend code.
- Use templates for password resets, receipts, etc.
- Keep transactional emails separate from marketing emails.
- Set SPF, DKIM, and DMARC records for your domain.
- Log delivery status and failures.
- Use webhooks if the provider supports bounce/open/delivery events.
Choosing a provider
- Postmark: excellent for transactional email
- SendGrid: flexible, widely used
- Mailgun: developer-friendly
- Amazon SES: low cost, more setup
- Resend: modern developer experience
If you want, I can show you:
- a working example in your backend language
- how to set up domain authentication
- how to send templated emails with one specific provider