Why Outbound Emails?
When you send an email via the Gmail API, the response only includes a message ID. The full email content (with headers, threading info, etc.) arrives asynchronously via Gmail’s push notifications. TheOutboundEmail model bridges this gap by:
- Recording intent immediately - Before calling Gmail, we store what you’re sending
- Correlating responses - When Gmail syncs the sent message, we link it back
- Tracking deliverability - Bounce notifications are automatically detected and associated
Lifecycle States
| Status | Description |
|---|---|
DRAFT | Email is being composed. Can be edited or scheduled with planned_send_at. |
PENDING | Send has been initiated but Gmail hasn’t confirmed yet. |
SENT | Gmail accepted the message. provider_message_id and provider_thread_id are populated. |
FAILED | Gmail rejected the send. Check error_message for details. |
Correlation & Tracking
When an email is sent successfully, we capture:provider_message_id- Gmail’s unique message ID (used to match the asyncEmailMessagerecord)provider_thread_id- Gmail’s thread ID (for conversation threading)message_id_header- The RFC 2822 Message-ID header (used for bounce correlation)
EmailMessage record with the OutboundEmail via email_message_uid.
Bounce Detection
Delivery failures (bounces) are detected automatically when syncing emails:- Detection - Messages from MAILER-DAEMON or with
multipart/reportcontent type are identified as DSN (Delivery Status Notification) messages - Correlation - The original message is found using the
In-Reply-Toheader ormessage_id_headermatching - Update - The
OutboundEmailrecord is updated with:delivery_status = "bounce_detected"bounce_detailscontaining recipient, status code, and diagnostic message
Context Linking
Outbound emails can be linked to domain entities (like invoices) using:context_type- The entity type (e.g.,"invoice")context_id- The entity’s UUID
Related Endpoints
- Send Email - Send an email immediately
- Prepare Email - Generate or resolve email content
- Save Draft (Create or Update) - Create or update a draft
- List Drafts - View all draft emails