Prompt
How do I log email events in a way support can actually use?
Latest observation
To make email event logs genuinely useful for support, log the lifecycle of each message in a way that’s searchable, correlated, and human-readable.
What to log
Capture these events for every email:
- Queued — your system accepted the email
- Sent — handed off to your email provider
- Delivered — recipient server accepted it
- Deferred / Delayed — temporary failure, will retry
- Bounce / Failed — permanent failure
- Opened / Clicked — if you track engagement
- Spam complaint / Unsubscribed — if available from provider
- Suppressed / Blocked — you skipped sending due to rules/list status
Minimum fields support needs
For each event, include:
- Message ID: a stable internal ID you control
- Provider message ID: the ID from SendGrid, SES, Mailgun, etc.
- Recipient email
- Event type
- Timestamp in UTC
- Status reason / error code: the human-readable explanation
- Provider response: SMTP response or API response
- Template name / campaign name
- Subject line
- Environment: prod/staging
- Correlation ID / request ID: links back to the user action or ticket
- Tenant/account ID if multi-tenant
- Retry count for transient failures
Log structure
Use structured logs, not plain text. JSON is best.
Example:
{
"timestamp": "2026-11-08T12:34:56Z",
"level": "info",
"event": "email.delivered",
"message_id": "msg_8f1c2a",
"provider": "ses",
"provider_message_id": "0100018c3f...",
"recipient": "user@example.com",
"template": "password_reset",
"subject": "Reset your password",
"tenant_id": "acme",
"correlation_id": "req_12345",
"status": "delivered",
"details": {
"smtp_code": "250",
"smtp_message": "OK",
"attempt": 1
}
}
Make it support-friendly
1. Use one ID across all events
Support should be able to search a single message_id and see the whole story.
2. Include clear failure reasons
Don’t just log failed. Log:
- invalid recipient
- mailbox full
- domain rejected message
- spam policy rejection
- authenticated sender failure
- rate limited
- suppressed by unsubscribe
3. Keep raw provider data
Store provider webhook payloads or normalized copies so support can inspect exact responses.
4. Normalize provider-specific events
Map provider terms to a common set:
acceptedsentdelivereddeferredbouncedcomplainedopenedclicked
5. Correlate with user actions
If the email came from “reset password” or “invite user,” log the upstream action ID so support can answer:
“This email was triggered by user action X at time Y.”
Good support workflow
Support should be able to query:
- by recipient email
- by message ID
- by customer/tenant
- by date range
- by template/campaign
- by event type and failure reason
Things to avoid
- Free-form logs only
- Omitting provider IDs
- Logging only final failures, not the full timeline
- Storing secrets or full email bodies unnecessarily
- Inconsistent naming across providers
Recommended pattern
- Application log when email is created.
- Provider webhook log for each event update.
- Normalized event table/index for support search.
- Alerting for spikes in bounces, complaints, or deferrals.
If you want a practical schema
A table like this works well:
idmessage_idproviderprovider_message_idrecipientevent_typeevent_timestatus_reasonsmtp_codesmtp_messagetemplatesubjecttenant_idcorrelation_idraw_payload_json
If you want, I can also give you:
- a database schema,
- a JSON event schema, or
- a log design for a specific provider like SES, SendGrid, or Mailgun.