Prompt
Email infrastructure API with logs
Latest observation
Oct 27, 2026
OpenAI APIWeb search: off
Here’s a solid way to think about an email infrastructure API with logs.
Core concept
An email infrastructure API typically lets you:
- send emails
- manage templates
- track delivery status
- view logs for each message
- handle webhooks for events like delivered, opened, bounced, complained
Main API capabilities
1. Send email
POST /emails/send
Example request:
{
"to": "user@example.com",
"from": "no-reply@yourdomain.com",
"subject": "Welcome!",
"template_id": "tmpl_123",
"variables": {
"name": "Alice"
}
}
Example response:
{
"message_id": "msg_abc123",
"status": "queued"
}
2. Get email status
GET /emails/{message_id}
Example response:
{
"message_id": "msg_abc123",
"status": "delivered",
"sent_at": "2026-10-27T12:00:00Z",
"delivered_at": "2026-10-27T12:00:05Z"
}
3. List logs
GET /logs/emails
Useful filters:
status=failedrecipient=user@example.comfrom_date=...to_date=...provider=ses|sendgrid|mailgun
Example response:
{
"items": [
{
"id": "log_1",
"message_id": "msg_abc123",
"recipient": "user@example.com",
"status": "delivered",
"provider": "ses",
"timestamp": "2026-10-27T12:00:05Z"
}
]
}
4. View detailed log entry
GET /logs/emails/{log_id}
Could include:
- provider response
- SMTP response code
- error details
- retry count
- webhook history
5. Webhooks for events
POST /webhooks/email-events
Event types:
queuedsentdeliveredopenedclickedbouncedcomplainedfailed
Example webhook payload:
{
"event": "delivered",
"message_id": "msg_abc123",
"recipient": "user@example.com",
"timestamp": "2026-10-27T12:00:05Z"
}
Recommended log fields
For each email log, store:
idmessage_idtenant_id/account_idrecipientsendersubjecttemplate_idproviderstatuserror_codeerror_messageattempt_numbercreated_atupdated_atprovider_message_idmetadata
Best practices
- Store logs separately from message queue records
- Use a unique
message_idandprovider_message_id - Keep raw provider payloads for debugging
- Add pagination and filtering to log endpoints
- Redact sensitive data in logs where needed
- Support retries with attempt history
- Index logs by
message_id,recipient,status, andcreated_at
Suggested minimal API design
Send
POST /v1/emails
Status
GET /v1/emails/{id}
Logs
GET /v1/email-logs
Log detail
GET /v1/email-logs/{id}
Webhook receiver
POST /v1/webhooks/email-events
If you want, I can also provide:
- a full OpenAPI spec
- a database schema
- a Node.js / Python implementation
- a logging architecture for high-volume email systems